API Contract Testing: Catch Breaking Changes Before Your Partners Do

API contract testing checks that an API provider and its consumers agree on the request and response format, such as fields, types and status codes, without running the whole system. Each side tests against a shared contract, so a breaking change fails a fast build check instead of a production release.

That shared agreement matters because most breaking changes look harmless to the team that makes them. For example, a backend developer renames customer_id to customerId, every unit test passes, and the release goes out on schedule. The next morning, a partner’s integration stops syncing orders, and shoppers notice before anyone on your team does.

Mismatches like that renamed field are what our engineers hunt for in API testing, comparing every response with what the calling apps expect. Since much of that work happens on products already in use, we add contract tests while development carries on as usual. Yet few teams have that safety net in place. According to Postman’s 2025 State of the API report, only 17% of respondents use contract tests, against 67% for integration tests.

If other teams or partners depend on your API, read on to see how contract tests work, where they run in a release pipeline, and how to tell whether your system needs them.

What Is API Contract Testing

API contract testing is a way to confirm that an API and the apps calling it still agree on the messages they exchange. Every test involves a provider, the team that owns the API, and at least one consumer. Between the two sits the contract, a written record of the requests the calling app sends and the responses it relies on.

That record usually takes the form of a short file listing:

  • The endpoint and HTTP method, such as GET /orders/{id}
  • The fields the consumer sends in the request
  • The fields the consumer reads from the response, and the data type of each
  • The status codes the consumer expects, including error responses

Because a contract lists only what one consumer uses, it also shows the provider which parts of the API are safe to change. Say your API returns 40 fields and the mobile app reads 6 of them. The app’s contract names just those 6, so your developers know the app won’t notice changes to the other 34. If no other contract mentions those 34 fields either, the team can rename or remove them without breaking anything.

Once the contract is written, the two sides can test their code separately, without waiting for each other. The consumer team runs its code against a mock of the API, a stand-in built from the contract that returns the agreed responses. Meanwhile, the provider team replays the contract’s requests against the real API and checks that every response still matches. Because neither side needs the other’s service running, API contract testing fits into a normal build.

Contract Testing vs Integration Testing vs End-to-End Testing

Contract testing vs integration testing is a common comparison, because both look at how services talk to each other. What separates the two methods is what has to be running during a test. Integration testing connects real services and confirms that data flows correctly between them, while a contract test checks each side separately against the agreed format. End-to-end testing goes a step further than either and drives the whole product the way a user would.

Contract vs. Integration vs. End-to-End Testing at a Glance
Contract testing
Integration testing
End-to-end testing

What does it check?

Contract testing

Agreed request and response format on each side

Integration testing

Data flow between connected services

End-to-end testing

Full user journeys

What must be running?

Contract testing

Only the service under test

Integration testing

Some services

End-to-end testing

All services

What does it catch?

Contract testing

Renamed, removed or retyped fields and changed status codes

Integration testing

Wrong data, broken configuration and failed connections

End-to-end testing

Broken user flows across the whole product

What does it miss?

Contract testing

Business logic, performance and wrong values in correct fields

Integration testing

Mismatches with consumers outside the test setup

End-to-end testing

Exact cause of a failure

Who usually owns it?

Contract testing

Developers on both teams

Integration testing

Developers and QA engineers

End-to-end testing

QA engineers

Contract tests catch format problems cheaply, which leaves your slower integration and end-to-end suites free to focus on how the product behaves. For a closer look at where each of those slower tests belongs, see our comparison of end-to-end vs integration testing.

Consumer-Driven vs Provider-Driven Contracts

Who writes the contract shapes the rest of the process. In consumer-driven contract testing, the teams calling the API each list what they need, and the provider runs all those expectations against every build. As a result, the provider knows exactly which fields are in use and who uses them. Consumer-driven contracts fit best when several internal teams call the same API and can agree on a shared workflow.

Provider-driven contracts start from the other end. Here, the API team publishes an OpenAPI schema describing every endpoint, and that document becomes the contract. Consumers test their code against the schema, while the provider confirms that the real API still matches its own description. This model suits a public API, where you can’t ask unknown developers to write tests for you.

Larger systems often combine the two models. For example, internal services share consumer-driven contracts, while the public edge of the product relies on the OpenAPI schema. Some tools can also compare consumer expectations directly with a provider’s schema, which spares the API team from replaying every consumer’s tests.

How Contract Tests Fit Into a CI/CD Pipeline

API contract testing works best when the pipeline runs it on every code change, next to the rest of your automated API testing. A typical setup has four steps:

  1. The consumer team writes down what the app needs. In practice, developers add contract tests to the codebase, and a passing run produces the contract file.
  2. The contract goes to a broker. The broker is a shared store that keeps each version of every contract and records which ones have passed verification.
  3. The provider verifies on every build. The provider’s pipeline pulls the latest contracts from the broker and replays them against the new code.
  4. A failed check blocks the deploy. Before any release, the pipeline asks the broker whether the new version works with everything already running in production. If the answer is no, nothing ships until the mismatch is fixed.

The failure message names the consumer and the field that broke, for example “the mobile app expects total as a number, but the API now returns a string.” With that detail in hand, the two teams can agree on a fix before any customer sees an error.

Could a release break your partners' apps?
Contact Us

When Contract Testing Pays Off and When It Does Not

API contract testing adds setup work, a broker to run and a new habit for every team involved. That effort pays off when:

  • Several services or partner integrations depend on the same APIs
  • Separate teams own the provider and the consumers
  • Releases go out often, so manual coordination can’t keep up
  • Old versions of your mobile app stay in use long after you ship a new one
API Contract Testing: Catch Breaking Changes Before Your Partners Do
How far a single renamed field travels when no contract test stands in its way.

On the other hand, contract tests are rarely worth the effort for a single monolith with one front end, where one team builds both. In that setup, shared code and ordinary integration tests already catch most mismatches. An internal API that changes once or twice a year is another poor fit, since a careful review of each change costs less than maintaining contracts.

If you’re unsure where your system sits, count how often a release from one team broke another team’s work over the past year. Two or more such incidents mean a pilot on a single service pair is worth considering.

Contract Testing for Public and Partner APIs

Public and partner APIs bring a harder problem: you rarely know every consumer, so nobody can hand you their expectations. As a result, API contract testing here relies on the published schema to carry the whole contract. For most REST APIs, that schema is written in the OpenAPI Specification format, and the pipeline checks every real response against it on each build. Schema validation like this catches drift, the gap that opens when the code changes and the documentation doesn’t. However, a schema can’t show which optional fields partners actually read, so versioning and deprecation warnings carry much of the protection.

Version numbers soften the blow of a breaking change, but only when they tell consumers which releases need attention. Postman’s 2025 report found that 60% of teams version their APIs, but only 26% follow semantic versioning. Without a scheme that flags breaking releases, partners can’t tell a safe update from a risky one until something fails.

Removing an endpoint needs a warning, too. The published schema is the first place to give one, since an OpenAPI document can mark any operation as deprecated. On the live API, consumers can get the same warning in every response through the Deprecation HTTP header, which became an internet standard in March 2025. Contract tests then confirm that the old endpoint keeps working until the announced shutdown date. For the other checks worth running before a public release, use our REST API testing checklist.

How QAwerk Adds Contract Tests to a Running Project

API contract testing can start at any stage, even on a product that has been live for years. We begin by mapping what each consumer calls, then pick the service pairs where a break would cost the most, usually payments, partner integrations and the mobile app. Covering those connections first protects the riskiest releases, and the remaining pairs follow at a pace your teams can absorb.

Results land where your developers already work. Every failed check shows up in the pipeline and in your team chat, naming the consumer, the endpoint and the field. Our engineers set up pipeline and chat reporting like this for the card-issuing API of Union54, where they tested each endpoint while it was still being built, before any front end existed. About 1,500 automated scenarios ran in the team’s Bitbucket pipeline, with every result posted to Slack.

Contract testing also needs someone who talks to both sides. When a check fails, our QA lead brings the provider and consumer developers into one conversation, explains what changed and agrees on a fix, so neither team has to chase the other.

Unsure which API changes are safe to ship? Talk to our API testers.

FAQ

Is contract testing the same as schema validation?

No, although the two overlap. Schema validation confirms that each API response fits the structure published in an OpenAPI document. API contract testing is narrower and stricter, because it checks the exact fields and responses each calling app depends on. A response can pass schema validation and still break a client app, for example when the API drops an optional field that a mobile app reads.

Does API contract testing replace integration testing?

No, the two answer different questions. A contract test asks whether two services still speak the same request and response format, and it runs without connecting anything. An integration test connects the real services to see whether the data they exchange is correct and the setup between them works. Teams that add contract tests often keep fewer integration tests, since format checks no longer need a full environment.

What tools are used for API contract testing?

A common starting point is Pact, an open-source tool for consumer-driven contracts with libraries for many programming languages. Java teams working with Spring often pick Spring Cloud Contract instead. For a specification-first approach, Specmatic turns OpenAPI and other API descriptions into executable contract tests. Public APIs can also add a schema validator to an existing test framework to check live responses.

When should a team start writing contract tests?

Start when a second team or an outside partner relies on your API and the API changes often enough to break their work. Until both are true, a quick conversation between the developers changing the API and those using it usually does the job. A system that is already live can adopt contract tests too, one connection at a time, starting with the links that have broken before.

Can contract testing work with third-party APIs you do not control?

Partly. You can’t make a third-party provider run your contract tests, but you can record what your code expects from that provider’s API. A scheduled check then compares those expectations with the published schema or sandbox. When the provider changes something, the check fails in your pipeline before the change reaches your users, and your own mocks of that API stay accurate.

See how we future-proofed Africa's first card-issuing API through test automation, resulting in $15M in seed funding.

Please enter your business email isn′t a business email