Skip to the page

What to test and why · core

Unit, integration and end-to-end tests; the pyramid vs the trophy

Unit tests check one small piece in isolation, integration tests check several pieces working together (for frontend: a component with its children, state and a mocked network), end-to-end tests drive the real app in a real browser, and the pyramid and trophy are two views on how many of each to write for the most confidence per minute.

The notes

What you must know

  • Static checks (TypeScript, ESLint) catch typos and type errors for almost no cost. Kent C. Dodds adds them as the base of the 'testing trophy'.
  • Unit: a pure function, a reducer, a hook's logic. Fast and precise, but they can pass while the feature is broken.
  • Integration (frontend meaning): render a real component tree with React Testing Library, real state, mocked network (MSW); interact like a user. The trophy says most of your tests should be here: 'Write tests. Not too many. Mostly integration.'
  • End-to-end: Playwright or Cypress against a running app (often with a real backend or staging). Highest confidence, slowest, most flaky; keep them for critical journeys (login, checkout, payment).
  • Test pyramid (Mike Cohn, Martin Fowler): many fast low-level tests, fewer high-level ones; avoid the 'ice-cream cone' of mostly manual/E2E tests. Push each check to the lowest level that can catch it.
  • Guiding principle: the more your tests resemble the way your software is used, the more confidence they give. Test behaviour, not implementation details (state variable names, private functions, CSS classes).
  • Plus: contract tests between services, visual regression for design systems, accessibility checks, and production monitoring.

The red pen

Common traps: mistake → fix

  • Mistake: "Unit tests are always the best investment"

    Fix: for UI, integration tests through the DOM catch more real bugs per test.

  • Mistake: "E2E tests for every edge case"

    Fix: they are slow and flaky; cover edge cases lower down and keep E2E for key flows.

  • Mistake: "Pyramid vs trophy is a right/wrong question"

    Fix: both say: get the most confidence for your time; the trophy just weights integration more for UI code.

Easy to hard

Questions interviewers ask, easy to hard

  1. How do you test a frontend app? What goes in unit vs integration vs E2E?
  2. What is the testing trophy and how is it different from the pyramid?
  3. What does 'test behaviour, not implementation' mean? Give an example of an implementation-detail test.
  4. You join a team with 0 tests and a buggy checkout. What do you write first and why?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview