What problem does contract testing solve, and what does it not replace?
Answer
Contract tests detect incompatible expectations between a service consumer and provider earlier and more cheaply than full environments. They do not replace provider logic tests, realistic end-to-end journeys, performance checks or production observability.
Strong answer includes
- consumer-provider compatibility
- fast feedback
- clear limits of contract tests
Practical example
A frontend team consumes an /orders API and writes a Pact contract expecting a totalAmount field as a number. When the backend team later changes it to a formatted string like '$45.00' during a refactor, the contract test fails in their CI pipeline before the change even reaches a shared staging environment. The team still runs full end-to-end tests before release, because the contract test alone wouldn't have caught a case where the total was calculated incorrectly but correctly typed.