Back to docs
Recipe

Contract Testing

Verify that your API provider and consumer agree on the shape of data before you deploy.

Contract testing sits between unit tests and full end-to-end integration tests. Instead of spinning up both services, you capture the HTTP request/response pairs that matter and replay them against each side independently.

The core loop

  1. Consumer generates a pact file from its test suite.
  2. Provider replays the pact against its real endpoint.
  3. Both sides publish verification results to a shared broker (Pactflow, a CI artifact, or a Git branch).
  4. The pipeline gates deployment when contracts match.

Why it matters

A provider that silently drops a field or changes a status code breaks every consumer that depends on it. Contract tests catch that regression in CI — minutes after the PR opens — instead of hours later in staging or production.

Getting started

Pick a framework that matches your stack. Pact (Rust core with JS, Go, Python, JVM wrappers) is the most mature. Spring Cloud Contract works well for JVM shops. For gRPC or AsyncAPI schemas, look at schema-first contract testing with tools like Specmatic.

Pro tip: Start with the three consumer-driven contracts that have caused the most production incidents. You will see value within the first sprint.