This sample project demonstrates Specmatic gRPC support which allows you to use your proto files for Contract Testing. Specmatic gRPC support can also help you use your proto files for service mocking, #nocode backward compatibility testing and more.
The specmatic-order-api-grpc-kotlin is a gRPC server application developed according to the following proto files, which can be found in the central contract repository:
The ContractTest class uses our JUnit extension to demonstrate how to use Specmatic to test specmatic-order-api-grpc-kotlin gRPC server app using the above proto files.
If you want to use Docker via TestContainers then you can refer to the ContractTestUsingTestContainer class.
- Java 17 or later
-
Clone the repository
git clone https://github.com/specmatic/specmatic-order-api-grpc-kotlin
-
Initialize and update the
specmatic-order-contractssubmodulegit submodule update --init --recursive --remote
-
Enable automatic submodule updating when executing
git pullgit config submodule.recurse true -
To run contract tests,
- Using gradle -
./gradlew clean test - Using docker -
- Run the application using
./gradlew bootRun - Run the tests
docker run --network host -v "$(pwd)/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "$(pwd)/build/reports/specmatic:/usr/src/app/build/reports/specmatic" -v "$PWD/src/test/resources/specmatic:/usr/src/app/examples" -e SPECMATIC_GENERATIVE_TESTS=true specmatic/specmatic-grpc test --protoc-version="3.23.4" --port=9090 --host=host.docker.internal --examples=examples
- Run the application using
- Using gradle -
-
In case you want to run just the gRPC server using Gradle you can execute
./gradlew bootRun