Contract Tests Basics (Stable Interfaces)
On this page
What Contract Tests Protect
Contract tests validate compatibility between a producer (API/service) and consumers. They reduce regressions caused by schema drift and breaking changes.
What to Assert
- Required fields exist and types match.
- Backward compatibility rules (optional fields added are OK).
- Error responses follow a stable format.
Operational Checklist
- Version your API/schema and document breaking rules.
- Run contract tests in CI for both producer and consumer changes.
- Prefer small, stable contracts over huge payload snapshots.
Failure Modes
- Schema drift: producers change payload and consumers break in prod.
- Snapshot brittleness: tests fail on irrelevant formatting changes.