Mid-LevelAPI & Integration Testing
Describe how you would test an API that depends on a third-party service.
- third-party APIs
- mocking
- service dependencies
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Layers of testing: (1) Unit tests with mocked third-party responses (fast, reliable). (2) Integration tests with a sandbox environment if the third-party provides one (Stripe test mode, Twilio test credentials). (3) Contract tests to verify your code handles the documented response shapes. (4) Synthetic monitoring in production to catch third-party outages. (5) Test error handling: timeouts, rate limits, malformed responses, partial outages. Never let your tests depend on a live third-party in CI.
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.