contract testing
Testing that an API’s real behaviour matches its written contract, and that its callers only rely on what the contract promises.
In more detail
Provider checks prove the service serves what the contract says; consumer checks record what real callers need. Run them before every deployment so an incompatible change fails in review, not in a client. Deliberately breaking the service and watching the checks fail proves they have teeth.
Examples
Validating real server responses against the shared Zod schema in CI and failing the build on any mismatch.In this course: The consumer records the requests it sends and the responses it needs; the provider replays them against its implementation. A renamed field or changed status then fails before deployment. Treat a failure as a compatibility decision: fix the provider, migrate the consumer or version the contract.Related terms
- consumer-driven contract testing — A contract-testing approach in which each consumer records the requests and responses it depends on, and the provider verifies it still satisfies all of them.
- API contract — The written promise an API makes about its operations, inputs, outputs and errors, which callers rely on while the code behind it changes.
- OpenAPI — A standard, language-neutral format for describing an HTTP API: its paths, operations, parameters, request and response schemas, errors and security.
- breaking change — A change that makes existing users of a program or interface stop working until they change something too.
- release gate — An automatic check that must pass before a change may be deployed.
- contract drift — When the data a server actually sends slowly stops matching what its clients expect, usually without anyone noticing until something breaks.
- integration test — A test that checks several real parts working together, such as the service talking to a real database.
- consumer and provider — The two sides of a contract test: the consumer calls an API and states what it needs, the provider serves it and verifies it keeps the promise.
- Pact — A widely used open-source tool for consumer-driven contract testing between services.
Taught in
- HTTP Methods And Status Codes — Modern API Architecture: REST, GraphQL & gRPC
- Problem Details: RFC 9457 — Modern API Architecture: REST, GraphQL & gRPC
- Mocking Dependencies — Modern API Architecture: REST, GraphQL & gRPC
- Contract Testing — Modern API Architecture: REST, GraphQL & gRPC
- API Contract Architecture: OpenAPI 3.1 & Schema Truth — Production Full-Stack Engineering
- Full-Stack System Verification: Capstone Integration — Production Full-Stack Engineering
- Implementing An OpenAPI Contract — Modern Java: Virtual Threads & High-Throughput Services
- Contract Testing Between Services — Automated Testing, TDD & Quality Engineering
- Code Review As A Quality Gate — Automated Testing, TDD & Quality Engineering
- What To Look For In A Review — Automated Testing, TDD & Quality Engineering