Mid-LevelTest Automation & Frameworks
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 instinctsYou can defend why your suite is shaped like a pyramid, a trophy, or a honeycomb.
- Locator disciplineYou rank selector strategies by stability and explain when to break the rule.
- Flaky test ownershipYou debug to a structural fix instead of retry-until-green.
- Parallelisation literacyYou know how your framework isolates state, fixtures, and database access across workers.