Skip to main content

How do you mock API responses in end-to-end tests and when should you?

  • API mocking
  • network interception
  • test isolation

Answer it first, then compare. Nothing here is saved or scored.

Model answer

Playwright route.fulfill() or Cypress cy.intercept() lets you mock API responses. Mock when: testing error states (500, timeout), testing UI with specific data shapes, isolating frontend from backend instability, testing edge cases hard to reproduce. Do not mock for: integration tests verifying real API behavior, smoke tests, or when testing data persistence. Best practice: have both mocked and real API test suites, run mocked in PR CI and real in nightly.

What interviewers listen for

  • Test architecture instincts
    You can defend why your suite is shaped like a pyramid, a trophy, or a honeycomb.
  • Locator discipline
    You rank selector strategies by stability and explain when to break the rule.
  • Flaky test ownership
    You debug to a structural fix instead of retry-until-green.
  • Parallelisation literacy
    You know how your framework isolates state, fixtures, and database access across workers.

See all 35 automation questions

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