What is contract testing and how does Pact work?
- contract testing
- Pact
- microservices
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Contract testing verifies that a consumer and provider agree on the API interface without needing both running simultaneously. Pact workflow: (1) Consumer writes tests defining expected requests/responses, generates a "pact" (contract file). (2) Provider runs the pact against its real implementation to verify compliance. (3) Pact Broker stores contracts and verification results. Benefits: catches integration breaks in CI without deploying all services. Essential for microservices where full integration environments are expensive.
What interviewers listen for
- Schema-first thinkingYou validate response shape before you assert on values, every time.
- Status-code literacyYou can defend why 401 vs 403 vs 422 matters for the consumer.
- Contract awarenessYou know when consumer-driven contract tests beat end-to-end checks.
- Auth fluencyYou can describe rotating tokens across parallel workers without secrets in logs.