Skip to main content

Contract Testing

Contract testing verifies that a service (the provider) and everything that calls it (the consumers) agree on the shape of their API — request format, response fields, status codes — without either side needing the other running to test against. It catches breaking API changes at build time instead of in staging or production.

In a microservices architecture, spinning up every dependent service just to run an integration test doesn't scale — it's slow, flaky, and gets worse with every service you add. Contract testing solves this differently: the consumer defines what it expects from the provider (a "contract"), and that contract is verified independently against both sides.

Consumer-driven contract testing, the most common variant (Pact is the best-known tool), works like this: the consumer team writes tests against a mock of the provider, which generates a contract file. That contract is then replayed against the real provider in its own CI pipeline — if the provider's actual response doesn't match what the consumer expects, the provider's build fails, before anything ships.

The result: teams can deploy services independently, confident that a breaking API change gets caught in the provider's own pipeline, not discovered by a consumer team debugging a mysterious failure three services downstream.