Implement consumer-driven contracts, publish to the Pact Broker, verify providers, use matchers for flexible matching, and gate deploys with can-i-deploy.
0 / 5 completed
1 / 5
What is consumer-driven contract testing with Pact?
Consumer-driven contracts: each consumer test describes what it sends and what it expects back. Pact records this as a JSON contract file. The provider runs these contracts against its actual implementation. If the provider fails a consumer's contract, CI catches the breaking change before it reaches production — without needing a running consumer service during provider tests.
2 / 5
What is the Pact Broker and what role does it play in a CI/CD pipeline?
Pact Broker: consumers publishPacts() after running their tests. Providers configure pactBrokerUrl in their verification step and run verifyPacts() which fetches the latest consumer pacts. The can-i-deploy CLI command queries the broker: "can consumer v1.5 be deployed to production given current provider versions?" — a safety gate in the deployment pipeline.
3 / 5
How does Pact handle provider verification without running the consumer?
Provider verification: the pact file is a JSON description of interactions. The Pact framework sends each interaction as a real HTTP request to the running provider, then asserts the response matches the consumer's expectation. Provider state callbacks (given("user 123 exists")) set up required database state before each interaction.
4 / 5
What are Pact matchers and why are they used instead of exact value matching?
Pact matchers: exact matching fails when the provider returns "name": "Jane" but the contract expected "name": "John" — even though the consumer only cares that a string name is present. like("John") matches any string, making the contract capture intent (structure) rather than test data (values). This prevents false failures from dynamic data.
5 / 5
What does the can-i-deploy tool check before deployment?
can-i-deploy:pact-broker can-i-deploy --pacticipant OrderService --version 1.5 --to-environment production returns yes/no based on whether all pact verifications for that version have passed. This prevents deploying a consumer whose contracts the provider has not yet verified, or deploying a provider that has broken a consumer's contract.