Pact Documentation
The official documentation for Pact, the best-known tool for consumer-driven contract testing between services. It explains how contracts are generated from consumer tests and verified against the real provider, and when contract testing is and is not the right tool, with implementations in more than ten languages.
Guide
Web Development
Pact Foundation
Intermediate
Free
What it is
Pact is an open source, code-first tool for testing integrations between applications with contract tests. In consumer-driven contract testing, each consumer's tests describe the requests it makes and the responses it relies on; running those tests produces a contract (a "pact"). The provider then verifies that contract against its real implementation in its own pipeline. The documentation calls this "contract by example": concrete request and response pairs rather than a full specification of every possible state.
Why it matters
In systems with many services, a change in one service can break another that nobody tested together. End-to-end environments that run everything at once are slow and fragile. Contract tests catch breaking changes between a consumer and a provider early, in each service's own build, and only test the parts of the API consumers actually use, so providers can change unused behaviour freely.
What the documentation covers
- How Pact works, with diagrams of the consumer and provider sides.
- Implementation guides for many languages; the documentation states there are Pact implementations in more than ten languages, including JavaScript, JVM languages, .NET, Go, Python, Ruby, Rust and PHP.
- Sharing contracts and verification results through a Pact Broker, and using them to decide whether it is safe to deploy.
- Message-based (asynchronous) contracts as well as HTTP.
- Guidance on when contract testing fits and how it relates to schema-based approaches such as OpenAPI.
Is it worth your time?
For API testers, at introduction level, yes: understanding what contract testing is and running the official JavaScript example sets you apart. Using it seriously requires cooperation between teams that own the consumer and provider, so it matters most in organisations with several internal services.
Free or paid?
Pact is free and open source. PactFlow is a separate commercial service that adds hosted brokering and extra features; you do not need it to learn or use Pact.
Common questions
Is it a replacement for functional API tests? No. Contracts check the shape of the conversation between services, not whether the business rules are right.
Should I use Pact for a public API? Consumer-driven contracts work best when you know the consumers. For public APIs, schema-based checks are usually a better fit.
Ready to start?
Opens on Pact Foundation in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.