API contract testing verifies that an API behaves the way its contract says it does: the endpoints, request and response shapes, status codes, and headers that the provider and its consumers agreed on. The contract is usually an OpenAPI description or a set of consumer expectations, and the tests run on every change, so a breaking change fails in CI instead of in production. Popular tools include:
- Pact for consumer-driven contracts
- Schemathesis and Specmatic for tests driven by the OpenAPI description
- Redocly Respect, which runs Arazzo workflows against a live API and checks every response against the OpenAPI description
A small change to a response field can break a mobile app or a downstream service even when every unit test passes. Contract tests catch that kind of change before it ships.

API contract testing is a method of verifying that an API follows a predefined agreement, or "contract," between the API provider and its consumers. The contract defines how the API is expected to behave, including:
- API endpoints and HTTP methods
- Request and response payload structures
- Expected HTTP status codes
- Required headers and authentication mechanisms
When API providers make changes, such as modifying response structures or removing endpoints, contract tests highlight the discrepancies right away. Because the contract is checked on every change, teams can iterate on services without accidentally breaking downstream consumers or integrations.

There are two primary approaches to contract testing:
- Consumer-driven contract testing (CDCT): Consumers define the contracts, and providers verify that their implementation meets those expectations. Providers learn exactly which fields and behaviors their consumers depend on.
- Provider-driven (spec-driven) contract testing: The provider publishes the contract, usually an OpenAPI description, and the implementation is tested against it. Consumers integrate against the same description. This approach gives providers more control over how the API evolves.
Services depend on each other's APIs, and teams need to ship changes without breaking each other. Without contract tests, teams end up:
- Spending hours debugging integration issues that could have been caught earlier
- Waiting for other teams to finish their services before testing their own
- Worrying about breaking changes in shared APIs
- Running slow, expensive end-to-end tests that don't pinpoint the problem

For years, teams have relied on the testing pyramid that Mike Cohn introduced in 2009:
- Unit tests (base): Fast, low-cost tests of individual components in isolation. Great for catching logic errors, but limited in scope.
- Integration tests (middle): Verify interactions between components. Good for catching interface issues, but slower, more complex to set up, and sometimes flaky.
- End-to-end (E2E) tests (top): Simulate real user scenarios across the whole system. Best for system-wide issues, but slow, expensive to maintain, and often brittle.
The pyramid suggests many unit tests, fewer integration tests, and minimal E2E tests. That works well for monolithic applications but falls short for microservices, where service boundaries and API contracts become the critical points of failure.

Contract tests sit between unit and integration tests and check each interaction between services against the agreed contract. They add:
- Precise failures: A failing contract test points at the endpoint, field, status code, or header that changed.
- Fast feedback: The tests run in CI on every change, so a breaking change fails the build instead of a deployment.
- Independent work: Consumers build against mock servers while providers change their services, and the contract tests tell both sides when they drift apart.

Consider an e-commerce platform with separate microservices for product catalog, user authentication, order processing, payment handling, and inventory management. When the product catalog team updates their API to include additional product metadata, several issues could arise:
- The order processing service might break if it strictly validates product responses
- The inventory management service could fail when trying to access products with the new structure
With contract testing in place:
- The product catalog team updates the API contract
- Automated tests verify that the implementation and all consumers can handle the new response format
- If any service breaks, the team is alerted before deploying to production
- The product catalog team works with affected teams to update their consumers
Contract testing pays off most in these situations:
- Microservices architecture: If one service updates its API, it can break consumers without warning. Contract tests catch these issues early and keep services compatible as they evolve.
- Independent team development: When separate teams manage different parts of a system, contract tests prevent miscommunication. The provider verifies its implementation against what consumers expect, which reduces surprises during integration.
- Third-party API integration: If your app depends on external services, test the parts of the third-party API you use against its schema, or mock its expected responses, to catch breaking changes before they impact users.
- CI/CD pipelines: Running contract tests on every code change catches API issues automatically and reduces the risk of deploying breaking changes.
- Evolving APIs: When your API is actively changing, contract tests help you manage versioning and backward compatibility, so existing consumers keep working as you add fields or endpoints.
The tools fall into three groups, depending on where the contract comes from:
- Consumer-driven tools, such as Pact, build the contract from the consumers' tests, and the provider verifies against it.
- Description-driven tools, such as Schemathesis, Specmatic, Prism, and Microcks, generate tests, mocks, or traffic validation from an OpenAPI or other API description. Dredd was a popular description-driven tester, but its repository was archived in 2024.
- Workflow tools, such as Step CI and Redocly Respect, run multi-step sequences of calls, and Respect also checks every response against the OpenAPI description.
| Tool | Approach | Contract source | Best for |
|---|---|---|---|
| Pact and PactFlow | Consumer-driven contract testing. Consumer tests generate pact files; providers verify them. PactFlow is the hosted broker and adds bi-directional testing against a provider's OpenAPI description. | Pact files from consumer tests | Microservices where teams own consumers and providers and need a "can I deploy?" check |
| Schemathesis | Property-based testing. Generates many requests from the schema and reports crashes and responses that don't match it. | OpenAPI, GraphQL | Finding edge cases and schema violations the team didn't think to test |
| Specmatic | Turns API specifications into executable contract tests and service stubs. Also runs Arazzo workflows. | OpenAPI, AsyncAPI, and other specification formats | Contract-driven development, with tests and stubs from the same specification |
| Dredd | Sends the requests described in the API description and compares the responses. | API Blueprint, OpenAPI 2 (OpenAPI 3 experimental) | Existing legacy suites only: the project is archived and no longer maintained |
| Prism | Mock server and validation proxy. | OpenAPI | Mocking an API before it exists, and validating live traffic against the description |
| Microcks | Mocking and contract-testing platform, and a CNCF project. | OpenAPI, AsyncAPI, gRPC, GraphQL, SOAP, Postman collections | Teams that mock and test many API styles in one place, often on Kubernetes |
| Step CI | Open-source framework for API tests written as YAML workflows. | Its own YAML workflows, which it can generate from OpenAPI | Multi-step tests across REST, GraphQL, gRPC, and other API types in CI |
| Redocly Respect | Runs Arazzo workflows against a live API and checks every response against the OpenAPI description. | Arazzo and OpenAPI | Multi-step workflow tests against a real server, with status code, content type, and schema checks on every step |
Respect is part of the open-source Redocly CLI. It sends real HTTP requests, passes data from one step to the next, and checks the status code, Content-Type, and response body schema of each step against the OpenAPI description, plus any success criteria in the Arazzo description. It doesn't generate consumer contracts like Pact or fuzz inputs like Schemathesis, so it fits teams whose contract is the OpenAPI description.
For mock server, workflow testing, functional testing, and performance testing tools, see API testing tools.
To test an API against its OpenAPI description, send real requests to a running instance of the API and compare each response with what the description declares: the status code, the content type, and the response body schema. With Redocly CLI, you can generate a starter test file from the OpenAPI description with generate-arazzo, then run it against your server with respect.
Lint the description first. A test is only as good as the contract, so make sure the OpenAPI description is valid:
npx @redocly/cli@latest lint openapi.yamlGenerate starter tests. The
generate-arazzocommand writes anauto-generated.arazzo.yamlfile with one workflow for each operation:npx @redocly/cli@latest generate-arazzo openapi.yamlThe generated file is a starting point, not a complete test suite. Add the
--with-aioption to have a locally installed AI CLI (Claude Code, Codex, or Cursor) redesign it into multi-step workflows. Review the result before you rely on it.Run the tests against your server. The
respectcommand sends each request and checks the response. Use--serverto point a source description at a different server, such as staging, and--inputto pass values like tokens:npx @redocly/cli@latest respect auto-generated.arazzo.yaml --server api=https://staging.example.com --input token=$API_TOKEN --verboseThe name before the
=in--serveris thenameof a source description in the Arazzo file.Run it on every pull request. Add the same command to CI. Use
--severityto downgrade checks to warnings while an API is in active development, and--json-outputor--har-outputto keep the logs.
For a guided example with a real API, follow Generate and run API tests with Respect or the tutorial Test API contracts using Redocly Respect.
Other ways to check an API against its description:
- Property-based testing: Schemathesis generates many requests from the schema to find inputs that break the API.
- Validation proxy: Prism, or the experimental Redocly CLI
proxycommand, sits between a client and the API and validates the traffic that passes through. - Traffic replay: The experimental Redocly CLI
driftcommand reads recorded HTTP traffic, such as a HAR file or gateway logs, and reports undocumented endpoints and schema mismatches.
Arazzo is a specification from the OpenAPI Initiative for describing sequences of API calls, or workflows. An Arazzo description references one or more OpenAPI descriptions, lists the steps in order, passes data between them, and states what success looks like.

That makes Arazzo a good format for contract tests:
- Workflows are machine-readable, so tools can run, test, and monitor them.
- Each step references an OpenAPI operation, so a runner knows which status codes, content types, and schemas to expect.
- The same workflow can run on a laptop, in CI, and against production.
Redocly Respect runs Arazzo workflows this way: it checks each step against the OpenAPI description and against the success criteria in the workflow. Learn more in How to test API workflows with Arazzo, or see which other tools support the format in Arazzo specification tools.
Common obstacles, and how to handle them:
Keeping tests up to date:
- Challenge: Small API changes, like renaming a field or changing a status code, quickly make hand-maintained tests go stale.
- Solution: Validate the contract automatically in your CI/CD pipeline. Tools that check the API against its OpenAPI description flag discrepancies before they cause problems.
Managing test environments:
- Challenge: Setting up and maintaining dedicated environments can be complex and resource-intensive.
- Solution: Use containers and infrastructure-as-code for consistent, reproducible environments. Run consumer tests against mock servers to reduce dependencies on shared infrastructure.
Dealing with third-party APIs:
- Challenge: External APIs may have rate limits, unpredictable downtime, or changing schemas.
- Solution: Describe the third-party endpoints you use, test against mock servers day to day, and run a smaller set of checks against the real API on a schedule.
Data variability and edge cases:
- Challenge: Covering a wide range of inputs without ballooning test complexity is hard.
- Solution: Focus contract tests on structure and types, add specific cases for critical edge scenarios, and use property-based tools for broad input coverage.
Flaky and slow tests:
- Challenge: Network delays, inconsistent environments, or dependency issues can make tests pass and fail unpredictably.
- Solution: Isolate API tests from unrelated dependencies, set clear timeouts, and keep contract tests focused on the API boundary.
- Write the contract first: Agree on the OpenAPI description, or on the consumer expectations, before you build the endpoint.
- Automate the checks: Run contract tests in CI on every change, and alert the owning team when one fails.
- Maintain the suite as APIs change: Version your contracts, update tests with every schema change, and run them in reproducible environments.
Respect runs wherever Redocly CLI runs: on developer laptops and in CI/CD pipelines. Use it to:
- Autogenerate starter tests from an OpenAPI description with
generate-arazzo - Chain requests, using values from one response in the next request
- Authenticate steps with OpenAPI security schemes through the
x-securityextension, or use mTLS - Run smoke tests against production or pre-production after releases
- Check the third-party APIs you depend on
Respect Monitoring, part of the Redocly platform on the Enterprise plan, runs the same Arazzo workflows on a schedule. It displays the results of each workflow in a chart, sends Slack or email notifications when workflows fail or succeed, and tracks SLAs for availability.
What's the difference between contract testing and integration testing? Both verify service interactions, but contract testing focuses on the API boundary: whether each side keeps the agreed contract. Integration testing runs the actual service implementations together.
Do I need contract tests if I already have end-to-end tests? Yes. End-to-end tests validate complete workflows, but they are slow, expensive to maintain, and don't easily pinpoint the cause of a failure. Contract tests give faster, more specific feedback about API compatibility.
What's the difference between Pact and OpenAPI-based contract testing? Pact is consumer-driven: consumers record what they need in pact files, and providers verify those files. OpenAPI-based tools such as Respect, Schemathesis, and Specmatic treat the OpenAPI description as the contract and test the implementation against it. Many teams combine both, or use PactFlow's bi-directional testing to compare consumer pacts with the provider's OpenAPI description.
How do I handle authentication in contract tests? Most contract testing tools let you add authentication to requests. In Respect, pass secrets with --input and mark them with format: password so they're masked in logs, or apply OpenAPI security schemes with the x-security extension. For consumer tests against a mock, you usually mock the authentication step.
Can contract testing work with GraphQL APIs? Yes, though it needs GraphQL-aware tools. Schema checks in the GraphQL ecosystem, such as Apollo's, make sure schema changes don't break existing queries, and Schemathesis can generate tests from a GraphQL schema.