Skip to main content

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 thinking
    You validate response shape before you assert on values, every time.
  • Status-code literacy
    You can defend why 401 vs 403 vs 422 matters for the consumer.
  • Contract awareness
    You know when consumer-driven contract tests beat end-to-end checks.
  • Auth fluency
    You can describe rotating tokens across parallel workers without secrets in logs.

Terms to know

See all 35 api testing questions

Written by , Senior QA Automation Engineer, 50+ QA candidate interviews conductedLast updated July 2026