Skip to content
RED SAGSkills
mediumAutomation Test Engineer interview question

When should automated tests mock external services, and when should they use real ones?

What the interviewer wants to hear

  • Mock to test error cases, edge data and for speed and stability
  • Real integrations needed to catch contract and configuration problems
  • Balance with contract tests
  • Keep a small number of true end-to-end tests
  • Risk of mocks drifting from reality

Model answer

Mocks are great when I need control and stability. Third-party services like payment gateways, SMS or maps can be slow, rate-limited or unavailable in test environments, and they rarely let me trigger errors like timeouts or a declined card. With mocks, using network interception in the UI or tools like WireMock for services, I can test those cases deterministically and fast. The risk is that mocks drift away from how the real service behaves, so tests pass while production breaks. To balance this, I keep a small number of tests that hit the real sandbox, run contract tests that verify our assumptions about the provider's API, and update mocks from recorded real responses. For our own internal services, I prefer real integration in a test environment for critical flows, and mocks for everything else.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Automation Test Engineer questions