Test Tools · API Testing

Pact

Consumer-driven contract testing. Ensures API consumers and providers stay in sync without deploying both sides at once.

Overview

Pact is an open-source contract testing framework that implements consumer-driven contract testing (CDCT). Instead of testing APIs via integration tests that require both consumer and provider to be running, Pact lets consumers define their expectations in a contract file. The provider then verifies it can meet those expectations independently.

Pact is particularly valuable in microservices architectures where dozens of services communicate via APIs. It eliminates the "deploy everything to test anything" problem and catches breaking API changes before they reach production.

What it's used for

Pact is essential when:

  • Microservices architecture: Many services calling each other's APIs — integration testing becomes a nightmare.
  • Independent deployment: Consumer and provider teams deploy on different schedules.
  • Breaking change prevention: Catch API contract violations in CI before they reach production.
  • Bi-directional contracts: Use Pact Broker to manage and version contracts across teams.

Pros & Cons

Pros

  • Eliminates brittle integration tests
  • Enables independent deployment of microservices
  • Catches breaking API changes in CI
  • Supports multiple languages (JS, Java, .NET, Python, Go, Ruby)
  • Pact Broker provides contract visibility across teams

Cons

  • Learning curve: CDCT is a paradigm shift from traditional integration testing
  • Not a substitute for all integration tests — some end-to-end validation is still needed
  • Requires discipline: contracts must be maintained as APIs evolve
  • Pact Broker adds infrastructure complexity
  • Limited support for event-driven architectures (improving with Pact v4)

Platforms & Integrations

Pact runs on Windows, macOS, and Linux. It supports JavaScript, Java, .NET, Python, Go, Ruby, and Rust. The Pact Broker is a separate service (Docker or SaaS).

Windows macOS Linux JavaScript Java .NET Python Go Ruby Rust REST GraphQL gRPC Message Queues Docker Pact Broker Jenkins GitHub Actions GitLab CI

Pricing

TierCostIncludes
Open SourceFreeAll language implementations, core features
PactFlow (SaaS Broker)From $99/moHosted Pact Broker, SSO, analytics, bi-directional contracts

NZ Context

Pact is gaining adoption in NZ fintech and SaaS companies with microservices architectures. Xero has publicly discussed contract testing as part of their quality strategy. For NZ teams moving from monoliths to microservices, Pact is often introduced after the first "integration test nightmare" incident. It requires organisational buy-in because both consumer and provider teams must participate.

Alternatives

  • Spring Cloud Contract — Java/Spring-specific contract testing with similar concepts.
  • OpenAPI + Schema Validation — Provider-driven approach. Less coupling but misses consumer-specific expectations.
  • Mountebank — Service virtualization for stubbing dependencies during testing.

Learn more