Software Testing & QA (50 Qs)•Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)
Consumer-Driven Contract Testing with Pact for Microservices.
senior LevelTestingMicroservices
In Simple Words: In a microservices architecture with 50 services, running full E2E environments for every PR is slow, expensive, and fragile. Consumer-Driven Contract Testing (Pact):
- Consumer Defines Contract: The frontend or downstream service writes unit tests defining the exact request it sends and the minimum response payload it needs. Pact outputs a
pact.jsoncontract file. - Provider Verifies Contract: The upstream backend API imports
pact.jsonand runs an automated test against its real controller endpoints. - If the backend changes a field type or deletes an endpoint, the contract test fails immediately in CI before deployment, guaranteeing cross-service compatibility without spinning up full E2E environments!