This repository demonstrates contract testing using PactFlow. It includes a consumer application and a provider application, with CI/CD examples for both consumer-driven and bidirectional contract testing.
- Overview
- Setup
- Consumer Application
- Provider Application
- Contract Testing
- CI/CD Integration
- Resources
Contract testing ensures that services (consumer and provider) can communicate with each other correctly. PactFlow is a platform that helps manage these contract tests, providing a way to publish and verify contracts.
./gradlew clean build
The consumer application simulates a client that makes requests to the provider. It uses Pact to define expected interactions with the provider.
The consumer calls /books
endpoint of the provider.
BookClientConsumerTest
is the consumer test written to generate contracts with the provider./gradlew runConsumerTest
for running the test using gradle command
The provider application simulates a service that the consumer interacts with. It uses Pact to verify that it meets the consumer's expectations.
BookProviderTest
is the test written to verify the contract against the consumer and publish the results to PactFlow.- To run the above test set environment variables for PACT_FLOW_BASE_URL and PACT_FLOW_TOKEN.
- The test will fetch the latest contract from PactFlow and verify the contract .
In consumer-driven contract testing, the consumer defines the interactions and expectations. These are then shared with the provider to ensure it meets the expectations.
Bidirectional contract testing uses PactFlow to automatically infer the provider's capabilities and verify against the consumer's expectations.
pact-consumer.yml
is the workflow to trigger the following set of steps:
- Run the consumer test to generate the contract.
./gradlew runConsumerTest
- Publish the contract using pact cli
- Can-I-Deploy
- Record Deployment
pact-provider.yml
is the workflow to trigger the following set of steps for consumer driven contract testing:
- Run the provider test pact verification.
./gradlew runProviderTest
- Can-I-Deploy
- Record Deployment
pact-bidirectional-provider.yml
is the workflow to trigger the following set of steps for bidirectional contract testing:
- Publish provider contract
- Can-I-Deploy
- Record Deployment