ReferenceAdvanced5-7 min reference
Pact
Pact is the most common consumer-driven contract testing tool. The consumer's tests generate a pact file; the provider replays it to prove it still honours the agreement. This is a fast reference for the workflow and CLI; for the underlying concepts see the Contract Testing Terms sheet, and for starter configs see the Configs library — both linked below.
The workflow
- Consumer test defines expected interactions → produces a
*.pact.jsonfile. - The pact is published to a Pact Broker (tagged with the consumer version + branch).
- Provider runs verification: replays each interaction against the real provider.
- Verification results are published back to the broker.
can-i-deploychecks both sides are compatible before release.
Key terms
| Term | Means |
|---|---|
| Pact file | JSON contract generated by the consumer |
| Mock provider | Stub the consumer tests against |
| Provider state | Precondition set up before an interaction ("user 1 exists") |
| Matcher | Match by type/regex, not exact value (like, eachLike, term) |
| Broker | Stores + shares pacts, tracks verification |
| Verification | Provider replaying the contract |
Commands you'll see
| Command | Does |
|---|---|
pact-broker publish ./pacts --consumer-app-version=$SHA | Publish contracts |
pact-broker can-i-deploy --pacticipant App --version $SHA --to-environment production | Release gate |
pact-broker create-version-tag | Tag a version (branch/env) |
| provider test task (per language) | Run provider verification |
When to use
Microservices with independent deploys where you need pre-deploy integration confidence. Use matchers, not exact values, so contracts don't break on dynamic data.
Common mistakes
- Asserting exact values instead of matchers → flaky contracts on timestamps/ids.
- Forgetting provider states, so verification can't set up its preconditions.
- Skipping
can-i-deploy, which defeats the point — you deploy incompatible versions. - Treating Pact as functional testing; it checks the contract, not the business logic.
// Related resources