We use analytics to count visits and form use. It is on unless you reject it. We show no ads on this site.

Glossary

Contract testing

Published . Last updated . Published by Zapple.Tech, founded by the founders of CodeceptJS and Codeception, open-source testing frameworks.

Published
Updated
Related service
API testing
Definition

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 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 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 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 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 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.

Contract testing: the consumer's tests write down the requests it sends and the responses it expects, and the provider replays them; each side is tested alone, without a shared environment

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 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.

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.

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 page.

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

  • API testing

    API testing checks a service directly through its interface rather than through a screen. Tests send requests to endpoints and verify responses, business rules, data and access rules. Our API testing services write automated API tests in your repository, covering contracts and back-end rules, and run them in your CI on every change.

  • Integration testing

    Integration testing checks the interfaces and interactions between components, or between your system and other systems and external services. It finds faults in the data they exchange and the flows that cross them. Our integration testing services write automated tests for your services, databases and third-party systems, and run them in your CI.

  • Service virtualization

    Service virtualization replaces a system your tests depend on, such as a payment provider or a service another team has not built yet, with a simulated version that answers like the real one. It lets you test when the dependency is slow, costly or missing. It pays off only if someone keeps the simulation in step with the real service.

  • Test pyramid

    The test pyramid is a model for spreading automated tests across levels: many fast unit tests at the base, fewer service tests in the middle, and few slow end-to-end tests through the user interface at the top. Mike Cohn described it as the test automation pyramid. It guides proportions, not exact ratios: tests higher up are slower and cost more.

All terms in the glossary

Test with AI

API testing

API testing services: automated tests for your APIs, microservices and service contracts, in your repository and run in CI on every change. One-week audit.

See the service

Questions about contract testing

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.

Request a QA audit quote

Tell us what you ship and what worries you.

What happens after you send this

  1. You send the form: your situation and what you need tested, then your name and work email.
  2. Within one business day, we reply with a suggested first step, its scope, timeline and a quote.
  • Fixed scope
  • You decide after each step
  • The tests live in your repository
  • An NDA signed before access

“They helped us to close the positions and consult our team how to proceed further. High-quality quick feedbacks with the deep checking of the required tasks, professional approach, great understanding of the company's technologies and product, detailed reports.”

Kristina Lavrentieva, Manager at keepgo.com, Israel
  • Rated 4.9 out of 5 on Clutch, from 7 client reviews
  • 42 completed test automation and infrastructure projects
  • Founded by the founders of CodeceptJS and Codeception, open-source testing frameworks

Request a QA audit quote

    What is closest to your situation?
    Optional. The product, the platforms, how often you release, what broke last.

    You decide after our reply whether to go ahead.

    Prefer to talk first? Book a call

    One-week QA audit · written report

    Request a QA audit quote