Mid-LevelAPI & Integration Testing
What is contract testing and how does it differ from integration testing?
- contract testing
- pact
- microservices
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Contract testing verifies that a provider API meets the expectations defined by consumer services, without deploying both together. Tools: Pact, Spring Cloud Contract. Integration testing deploys both services and tests actual communication. Contract testing is faster, runs in isolation, and catches breaking changes early. Use contract testing when: many consumers depend on an API, teams deploy independently, or integration environments are costly. The contract is a shared agreement, not a full integration test.
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.