This sample project demonstrates how we can practice contract-driven development and contract testing in a REST (Kotlin) API that depends on an external GraphQL domain service. Here, Specmatic is used to stub calls to domain graphQL API service based on its GraphQL specification, and also to contract test the REST API itself based on its own OpenAPI specification.
- Checkout the BFF project from here, and start it up using the instructions in it's README.
- Execute this command:
- On Unix and Windows Powershell:
./gradlew bootRun- On Windows CMD Prompt:
gradlew bootRunLook at the ContractTest class to see how the GraphQL dependency has been stubbed out.
Execute this command to run the contract tests:
- On Unix and Windows Powershell:
./gradlew test- On Windows CMD Prompt:
gradlew test- On Unix and Windows Powershell:
docker run --rm -p 8080:8080 -v "$(pwd)/specmatic.yml:/usr/src/app/specmatic.yml" -v "$(pwd)/src/test/resources/specmatic/graphql/examples:/usr/src/app/examples" specmatic/specmatic-graphql virtualize --port=8080 --examples=examples- On Windows CMD Prompt:
docker run --rm -p 8080:8080 -v "%cd%/specmatic.yml:/usr/src/app/specmatic.yml" -v "%cd%/src/test/resources/specmatic/graphql/examples:/usr/src/app/examples" specmatic/specmatic-graphql virtualize --port=8080 --examples=examples- On Unix and Windows Powershell:
./gradlew bootRun- On Windows CMD Prompt:
gradlew bootRun- On Unix and Windows Powershell:
docker run --rm --network host -v "$(pwd)/specmatic.yml:/usr/src/app/specmatic.yml" -v "$(pwd)/build/reports/specmatic:/usr/src/app/build/reports/specmatic" specmatic/specmatic test --port=8070- On Windows CMD Prompt:
docker run --rm --network host -v "%cd%/specmatic.yml:/usr/src/app/specmatic.yml" -v "%cd%/build/reports/specmatic:/usr/src/app/build/reports/specmatic" specmatic/specmatic test --port=8070