# Contract testing

> Contract Testing: What It Is and What It Does Not Catch. Canonical page: <https://zapple.tech/glossary/contract-testing/>

Contract testing checks an integration point by testing each application in isolation against a shared contract that records the messages one side sends and the other expects. The caller is the consumer and the responder is the provider. It catches a breaking API change without deploying both services, but it does not prove the whole flow works.

## How does contract testing compare with integration testing?

Both check that two services work together. They differ in what has to be running and what a failure tells you.

| | Integration test | Contract test |
|:--|:--|:--|
| What runs | Both services, often with a database and other dependencies | One service at a time, against a recorded contract |
| What it proves | The real chain works in that environment | Each side keeps its part of the agreed messages |
| Where a failure points | Somewhere in the chain, often after deployment | At the request and response that no longer match the contract |
| Environment needed | A shared test environment | The developer's machine or the CI job |
| Weak spot | Expensive and brittle, in Pact's words | Anything nobody wrote into the contract, and the whole flow |

The [Pact documentation](https://docs.pact.io/) argues that without contract testing, the only way to know applications work together is expensive and brittle integration tests. That is the project's view of its own technique. A contract test does not check the whole flow, so add contract tests next to a small set of integration tests instead of removing those. Our [integration testing services](/services/integration-testing-services/) page covers the chain-level checks.

## What are consumer-driven and provider-driven contracts?

A contract sits between a consumer, the application that makes a request, and a provider, the application that answers. Two styles exist.

In the consumer-driven style, the consumer's own tests produce the contract. The [Pact JS documentation](https://docs.pact.io/implementation_guides/javascript/docs/consumer) says the consumer writes a test that sets out its assumptions and needs, and the library writes the interactions to a contract file. The provider replays them to confirm it can meet them. Pact's introduction notes that only the parts of the communication the consumers use get tested, so provider behavior no consumer uses is free to change without breaking tests.

In the provider-driven style, the provider's documentation is the contract. The [OpenAPI Specification](https://spec.openapis.org/oas/v3.2.1.html) defines a standard, language-agnostic description of HTTP APIs, and tests check the provider against that document. The Pact introduction points out that this on its own gives no test-based assurance that consumers call the provider correctly. Names vary between tools: Pact calls this provider contract testing, and the [Spring Cloud Contract](https://docs.spring.io/spring-cloud-contract/reference/) documentation says it lets you perform "consumer-driven and producer-driven contract testing".

A schema describes every possible state of a resource. A Pact contract, in Pact's own words, is "contract by example": each test case describes one concrete request and response.

## When is contract testing worth it, and when is it not?

It is worth it when several teams own services that call each other and a change by one team can break another without anyone noticing until a shared environment goes red. That is typical of microservices, and of a web or mobile client calling an API that another team deploys. The [Pact JS overview](https://docs.pact.io/implementation_guides/javascript/readme) lists the benefits the project claims, among them local tests, faster deploys and less reliance on complex test environments. Treat those as the tool's claims, not a measurement of your system.

Our rule of thumb: skip it when a single team owns both sides and deploys them together, because a normal integration test covers the same risk with less setup. We would also expect little from it if the API changes rarely, or if nobody will maintain the contract files and the process that shares them between teams.

If you are weighing it against broader API checks, see our guide to [API test automation](/blog/types-of-automation-testing/what-is-api-test-automation/).

## What mistakes do teams make with contract testing?

- **Treating it as a replacement for integration tests.** A contract says nothing about the whole flow. Keep a small set of end-to-end checks on the paths that carry revenue.
- **Writing contracts by hand to match the whole API.** In the consumer-driven style, the contract should record what the consumer uses. A contract copied from the full response makes harmless provider changes look breaking.
- **Verifying against a stale contract.** The provider has to verify the latest contracts from every consumer in CI, otherwise the check passes while the real client has moved on.
- **Skipping the ownership question.** When a contract test fails, someone has to decide whether the consumer or the provider changes. Agree who decides before the first failure.
- **Mixing up two meanings of the term.** Pact notes that "contract testing" is sometimes used for checking a provider against its own documentation, such as an OpenAPI file. That is useful, but it is a different check from testing the consumer and the provider against the same contract.

For the distributed-systems problems contract testing addresses, and a consumer-driven workflow demo, see Bas Dijkstra's recorded talk [Improving your integration testing efforts with contract testing](/blog/types-of-automation-testing/bas-dijkstra-improving-your-integration-testing-efforts-with-contract-testing/).

## What does Zapple.Tech do about it?

If you are not sure whether your services need contract tests, integration tests or neither, start with the evidence. Zapple.Tech starts with a one-week QA audit of one product area. It looks at its tests, pipeline and release process, and ends in a written report on what is at risk and what to fix first, plus a pilot plan you can run with Zapple.Tech or without it. Read more on the [QA audit and assessment](/services/audit-and-assessment/) page.

When the plan includes API-level checks, [API and server-side test automation](/services/api-server-side-test-automation/) covers building them. Tell us about your services in the form below. More terms are in the [QA glossary](/glossary/).

## FAQ

### What is contract testing?

Contract testing is a technique for testing an integration point by checking each application in isolation to see that the messages it sends or receives match a shared contract. For an HTTP API, the messages are the request and the response. The consumer and the provider are each tested against the contract, so a breaking change shows up without deploying both services.

### What is the difference between contract testing and integration testing?

An integration test runs the real services together and checks that they work as a chain. A contract test checks each side alone against an agreed record of the messages between them. A contract test needs only one side running, so it can run locally, and a failure points at one request and response. It does not replace a check that the whole flow works.

### What is consumer-driven contract testing?

In consumer-driven contract testing, the application that calls an API writes tests that record what it actually uses, and the contract is generated from those tests. The provider then verifies it can meet them. Parts of the provider that no consumer uses can change without breaking a contract test.

### What does contract testing not catch?

It does not show that a business flow works across services, that the system performs under load, or that the data in a real environment is right. It checks only the interactions that someone wrote into the contract. A field no consumer test uses can change unnoticed.

## Sources

- [Pact documentation, Introduction (updated 2026-12-02)](https://docs.pact.io/)
- [Pact JS documentation, Overview (updated 2026-07-22)](https://docs.pact.io/implementation_guides/javascript/readme)
- [Pact JS documentation, Consumer tests (updated 2026-07-22)](https://docs.pact.io/implementation_guides/javascript/docs/consumer)
- [OpenAPI Specification v3.2.1 (published 2026-09-10)](https://spec.openapis.org/oas/v3.2.1.html)
- [Spring Cloud Contract reference documentation (stable 5.0.3)](https://docs.spring.io/spring-cloud-contract/reference/)
