| name | contract-testing |
| description | Consumer-driven contract testing for microservices using Pact, schema validation, API versioning, and backward compatibility testing. Use when testing API contracts or coordinating distributed teams. |
| category | testing-methodologies |
| priority | high |
| tokenEstimate | 900 |
| agents | ["qe-api-contract-validator","qe-test-generator","qe-security-scanner"] |
| implementation_status | optimized |
| optimization_version | 1 |
| last_optimized | "2025-12-02T00:00:00.000Z" |
| dependencies | [] |
| quick_reference_card | true |
| tags | ["contract","pact","consumer-driven","api","microservices","schema-validation"] |
| trust_tier | 3 |
| validation | {"schema_path":"schemas/output.json","validator_path":"scripts/validate-config.json","eval_path":"evals/contract-testing.yaml"} |
Contract Testing
<default_to_action>
When testing API contracts or microservices:
- DEFINE consumer expectations (what consumers actually need)
- VERIFY provider fulfills contracts (Pact verification)
- DETECT breaking changes before deployment (CI/CD integration)
- VERSION APIs semantically (breaking = major bump)
- MAINTAIN backward compatibility for supported versions
Quick Contract Testing Steps:
- Consumer: Define expected request/response pairs
- Provider: Verify against all consumer contracts
- CI/CD: Block deploys that break contracts
- Versioning: Document supported versions and deprecation
Critical Success Factors:
- Consumers own the contract (they define what they need)
- Provider must pass all consumer contracts before deploy
- Breaking changes require coordination, not surprise
</default_to_action>
Quick Reference Card
When to Use
- Microservices communication
- Third-party API integrations
- Distributed team coordination
- Preventing breaking changes
Consumer-Driven Contract Flow
Consumer → Defines Expectations → Contract
↓
Provider → Verifies Contract → Pass/Fail
↓
CI/CD → Blocks Breaking Changes
Breaking vs Non-Breaking Changes
| Change Type | Breaking? | Semver |
|---|
| Remove field | ✅ Yes | Major |
| Rename field | ✅ Yes | Major |
| Change type | ✅ Yes | Major |
| Add optional field | ❌ No | Minor |
| Add new endpoint | ❌ No | Minor |
| Bug fix | ❌ No | Patch |
Tools
| Tool | Best For |
|---|
| Pact | Consumer-driven contracts |
| OpenAPI/Swagger | API-first design |
| JSON Schema | Schema validation |