A small API response change can pass a provider’s own pipeline yet break a consumer in production. Contract testing catches this compatibility gap by recording the requests a consumer makes and the responses it expects, then checking that the provider still honors those expectations before deployment. section 1.0 section 1.1
A contract is commonly a JSON artifact describing the two systems and their interactions. Unlike a traditional API integration test, the consumer and provider do not need to run against each other directly: each works through the shared contract. This brings API-level confidence earlier, without relying on a dedicated integrated environment. section 1.1 section 1.6
A renamed response field
A web application expects fullName from a User API. If the API changes that field to name, the systems become incompatible. A verified contract flags the change before release, so the teams can agree on an updated contract or revert the breaking change. A mobile consumer can separately contract for an added favorites field without changing what the web application expects. section 1.2
In consumer-driven contract testing, the workflow separates responsibilities:
- The consumer defines an interaction with a mock provider: a request it will send and the response it needs. Its unit-time test produces a contract and publishes it to a shared broker. section 1.4.1
- The provider downloads the contract, replays the expected request against its real implementation, and compares its actual response with the contracted response. section 1.4.2
- Both consumer and provider tests must run; a generated but unverified contract does not prevent provider breaking changes. section 2.0
Figure 1.5 A contract test between a consumer and a mock data provider
This diagram shows the consumer-side loop: define an interaction against a mock provider, run the consumer test, and generate the shared contract. section 1.4.1
Contract testing fits between unit and integration testing in the test automation pyramid. It complements rather than replaces unit, integration, and end-to-end tests: use it for compatibility expectations, not all provider behavior. Provider business logic and side effects remain functional-test concerns; UI, accessibility, security, and performance need their own testing approaches. section 2.1.5 section 1.3
It is especially useful across microservices or other connected systems, including web or mobile applications and APIs, where full integration or end-to-end suites become slow and difficult to scale. Contracts can run locally and in CI, helping teams find mismatches before they reach shared environments or production. section 1.3 section 2.3.1
Adopt incrementally. Secure buy-in from both sides of an integration, start with one new test or a converted integration test, and prefer a simpler new API over a difficult legacy service. Explain the operational reason—such as flaky integration tests or safer releases—then make progress and outcomes visible. section 2.4.1 section 2.4.2 section 2.4.3



