Glossary

Contract Testing

Contract testing is a type of testing that verifies the agreement between API consumers and providers. Instead of running both services simultaneously, each side verifies the contract independently.

The problem it solves

In a microservices architecture, service A expects service B to return a field user_id, but B renamed it to userId. Integration tests do not always catch such changes in time.

Consumer-Driven Contract Testing

  1. The consumer (A) records expectations in a "contract" (pact file)
  2. The contract is published to a Pact Broker
  3. The provider (B) automatically verifies that it meets the contract
  4. If B changes its API — the test fails before deployment

Tools

Pact — the most popular framework. Supports PHP, Node, Java, Go and others. Pact Broker — centralised contract storage.