Consumer-driven contracts: verify consumer expectations with Pact before deployment
Consumer-driven contract (CDC) testing records only the requests and responses a consumer actually depends on, then checks whether the provider satisfies them. With Pact, consumer tests interact with a mock provider and create a pact file; provider tests replay its requests against provider code and verify the results. This checks an integration boundary. It is not an end-to-end test of the whole system or proof of every business outcome.
Consumer-driven contract (CDC) testing records only the requests and responses a consumer actually depends on, then checks whether the provider satisfies them. With Pact, consumer tests interact with a mock provider and create a pact file; provider tests replay its requests against provider code and verify the results. This checks an integration boundary. It is not an end-to-end test of the whole system or proof of every business outcome.
Define actual expectations on the consumer side
In consumer tests, exercise the method, path, required headers, request fields, and response fields the consumer really uses.
Configure the mock provider to return the expected response, then check that consumer code builds the request and handles the response. Pact records this interaction as a JSON contract.
Publish the pact from consumer CI to a Pact Broker. Include consumer name, version, and branch so contracts from different builds and environments can be distinguished.
Put only consumer dependencies in the contract. If the consumer reads status and orderId, those fields and their formats may be expectations; the provider's internal database schema need not be. Test error interactions too when consumer code handles them differently.
Verify at the provider and share results
In provider CI, fetch the pact to verify from the Broker, prepare provider state, and send each request to the actual application. Consumer and provider may use different languages or frameworks, so use the Pact tools for each project's language.
Verify provider responses against the pact and publish verification results to the Broker from CI. Pact docs state that results can be published only for pacts retrieved from the Broker. Verification against only a local file does not automatically appear in the Broker's integration matrix.
Record consumer and provider versions, branches, and deployment environments. Both teams need the Broker results to decide which combinations are safe to deploy together.
Pact verification checks whether request/response interactions satisfy the contract. Use separate provider functional or integration tests to establish whether a payment settled, an event reached the right service, or the expected data was stored.
Connect deployment decisions to can-i-deploy
After consumer and provider CI publish results and record deployed versions/environments, run Pact Broker CLI can-i-deploy before the actual deployment. It checks whether the specified version is deployable to the target environment based on known contract verification results. Configure the pipeline to stop that deployment step on failure. Query the exact version and environment being deployed, and ensure results are current; stale or missing verification evidence can otherwise mislead.
When a new consumer contract requires a feature the provider has not implemented yet, consider Pact Broker's pending pacts feature. A failed verification for a pending pact may not fail the provider build, but the failure remains recorded in the Broker and the new consumer still cannot pass its deployment check. This lets the provider continue deploying other combinations with already supported contracts while protecting them from breakage. Branch/version metadata and tool settings must be correct, so follow the instructions for the Pact implementation in use.
What does the evidence cover?
**CDC is useful for:** detecting when a provider change disagrees with paths, headers, fields, status codes, or matching rules a consumer uses.
**Other tests are still needed for:** behavior not in the consumer contract, full authentication/authorization, throughput, recovery, and business side effects such as persistence or payment settlement.
**Contracts that are too narrow:** may omit an error, default, or field the consumer truly relies on and miss a regression.
**Contracts that are too broad:** may freeze incidental details and unnecessarily block safe provider changes.
“All pacts pass” is not the only completion criterion. Check that consumer contracts reflect real use, provider results are published for the correct version, and deployment checks reflect the target environment. Test business behavior outside the contract separately.
Sources
[Pact specification: how consumer-driven contract testing works](https://docs.pact.io/implementation_guides/pact_specification)
[Pact Broker: publishing provider verification results and deployment checks](https://docs.pact.io/pact_broker/advanced_topics/provider_verification_results)
[Pact Broker setup checklist](https://docs.pact.io/pact_broker/set_up_checklist)
[Pact Broker: pending pacts behavior and limits](https://docs.pact.io/pact_broker/advanced_topics/pending_pacts)