Contract Testing
When to use
- Building microservices that need integration confidence
- Replacing brittle integration tests with faster contract tests
- Detecting breaking API changes before deployment
- Setting up provider verification in CI
Core principles
- Consumer drives the contract — the client defines what it actually needs
- Provider verifies against consumer contracts — not against a human-written spec
- Contracts live in Pact Broker — visible to all teams, tracked over time
- State handlers make tests reproducible — provider sets up data for each interaction
- Can-I-Deploy check — never deploy a provider that breaks a consumer contract
References available
references/consumer-pact-test.md— PactV3 setup, MatchersV3, interaction definition, executeTestreferences/provider-verification.md— Verifier config, stateHandlers, Pact Broker publish, CI flagsreferences/openapi-validation.md— express-openapi-validator middleware, validateResponses in stagingreferences/can-i-deploy.md— pact-broker CLI check, CI gate before deploy, exit code semantics