Contract Testing Explained
Verify API compatibility between services at build time — catching breaking changes before they cause integration failures in production.
Contract Testing
Contract testing verifies that services conform to the API contracts expected by their consumers, catching breaking changes at build time before they cause integration failures in production.
Explanation
In microservices architectures, services depend on each other's APIs. A change in one service's response format can break all consuming services. Contract testing addresses this: consumers define contracts (expected requests and responses), and providers verify they satisfy those contracts. Consumer-driven contract testing (using Pact) lets each consumer specify what it needs, and the provider verifies it meets all consumer expectations. This catches breaking changes without requiring full end-to-end test environments, running quickly as part of CI/CD.
Bookuvai Implementation
Bookuvai implements contract testing with Pact for microservices projects. Consumers publish contracts to a Pact Broker, providers verify against all consumer contracts in CI, and breaking changes are caught before merge. This enables independent service deployment with confidence.
Key Facts
- Verifies API contracts between service consumers and providers
- Consumer-driven: consumers define expected requests and responses
- Catches breaking changes at build time, not in production
- Pact is the leading consumer-driven contract testing framework
- Enables independent service deployment in microservices
Related Terms
Frequently Asked Questions
- How is contract testing different from integration testing?
- Integration testing runs both services together. Contract testing runs each service independently against a contract, making it faster and more reliable. Contract tests can run in CI without spinning up dependent services.
- What is a Pact Broker?
- A Pact Broker is a server that stores contracts and verification results. Consumers publish contracts; providers fetch and verify them. The broker tracks which versions are compatible, enabling safe deployment decisions.
- Can I use contract testing with REST and GraphQL?
- Yes. Pact supports REST APIs natively. For GraphQL, contract testing verifies query schemas and response shapes. Both ensure consumers and providers agree on the API interface.