Testing a feature · Trade-off
What to unit test, integration test and end-to-end test
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
For a React app with a cart and a checkout, how do you decide what to cover with unit tests, integration tests and end-to-end tests? Where would most of your tests go?
Then
Follow-ups the interviewer asks next
- What do you mean by an integration test in a React app?
- Why not test everything end to end?
- What would you never unit test?
- Your team has 90% coverage, but bugs still reach production. Why?
- You have one week before launch and almost no tests. What do you write first?
- Where do contract tests and visual tests fit?
- How does this change for the React Native app?
- In your experience, what kind of test caught the most bugs?
The answer
What a strong answer covers
- Unit: pure logic with many cases (price totals, coupon rules, reducers, formatters).
- Integration, where most tests go: a feature rendered with Testing Library, with real child components and the network mocked by MSW, asserting what the user sees and can do.
- End to end: a few critical journeys (search, cart, pay) in a real browser against a test environment.
- Trade-offs: end-to-end tests are slow, costly and flakier but closest to reality; unit tests are fast but miss wiring bugs.
- Coverage is not quality: tests of implementation details, or tests that mock everything, give false confidence.
- One week: end-to-end tests for checkout and login first, then integration tests for the cart.
- Contract tests for API shapes, visual tests for the design system, and static checks (TypeScript, ESLint) as the base layer.
- React Native: Jest with React Native Testing Library, plus Maestro or Detox for a few device flows.
The red pen
Common traps
Avoid:"100% coverage is the goal"; only snapshot tests; mocking the component being tested.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.