Notes
The pyramid
The test pyramid, made popular by Mike Cohn, has three layers. At the bottom, many unit tests that check small pieces of code. In the middle, fewer service or API tests that check parts working together. At the top, a few UI tests that drive a real browser. Higher up, tests are slower, cost more to write and keep, and flake more, but they are more realistic. Lower down, they are fast, cheap, and point straight at the broken line.
/ UI \ few
/---------\
/ service \ some
/-------------\
/ unit \ many
higher up: slower, costlier,
more realistic, more flaky
lower down: faster, cheaper,
points at the exact bug Why the shape
Why that shape? Speed and precision. A unit test takes milliseconds, and when it fails it points at one function. An API test takes tens of milliseconds to a second, and points at one endpoint. A UI test takes seconds, and when it fails the bug could be in the page, the API, the data or the network. A thousand unit tests run in seconds. A thousand browser tests can take hours, which no developer waits for.
- unit ~ milliseconds fails → one function
- API ~ tens of ms to a second fails → one endpoint
- UI ~ seconds to tens fails → somewhere in UI, API, data or network
- 1,000 unit tests: seconds
- 1,000 UI tests: often hours
Choose the layer
The rule of thumb: test each rule at the lowest layer that can catch its bug. ShopRung's money rules, coupons, rounding and shipping, are pure calculations, so all their boundaries belong in unit tests. The quantity limit and the order states are enforced by the API, so API tests cover them, including the invalid moves. Privacy needs two users, still at the API. The browser is kept for what only a browser can show: one checkout journey from start to end.
- PRICE-3, 6, 9 money rules → unit: all boundaries
- CART-2 quantity limit → API: 0, 1, 10, 11
- ORD-4 order states → API: valid + invalid
- ORD-7 privacy → API with two users
- checkout journey → UI: one happy path
The trophy
The testing trophy, from Kent C. Dodds, is a different shape for modern web apps. At the base, static checks: types and linting catch whole classes of bugs for free. Then some unit tests. The biggest part is integration tests, which check pieces working together with few mocks, because that is where the confidence is. A small top of end to end tests. The idea: most of your confidence should come from tests that resemble how the software is used.
___ e2e ___
|integration| ← most
| |
\ unit /
\_______/
static
static: types, linting
"write tests, not too many,
mostly integration" Pyramid or trophy?
Pyramid or trophy? They agree more than they disagree. Both say: keep end to end tests few, and get fast feedback first. The pyramid leans on unit tests, which fits back ends full of business logic, like ShopRung's pricing. The trophy leans on integration tests, which fits front ends and services that mostly connect things. The honest answer in an interview: pick the shape by where your bugs actually live, and measure it.
- both: few end-to-end tests
- both: fast feedback first
- pyramid: unit-heavy, fits logic-rich back ends
- trophy: integration-heavy, fits UI apps and services with thin logic
- pick by where YOUR bugs live
The ice-cream cone
The shape to avoid is the ice cream cone: lots of manual testing on top, then many UI tests, few API tests, and almost no unit tests. It is common in teams that started automation from the UI. The symptoms are familiar: a suite that takes hours, fails randomly, and that nobody trusts when it goes red. The fix is gradual: when a UI test checks a rule, move that check down to an API or unit test, and keep the UI test only for the journey.
\ manual tests /
\--------------/
\ UI tests / many
\----------/
\ API / few
\------/
\unit/ almost none
symptoms: 3-hour suite, flaky,
nobody trusts red builds Contract and component
Real suites have more than three layers. Component tests check one piece of the user interface in isolation, like a cart table, without the whole app. Contract tests check that two services agree on an API, so they can be tested apart; you will meet Pact in Part four. Visual and accessibility checks usually ride along with UI tests, which is Part five. The shapes are a guide for balance, not a strict count.
- component tests: one UI component in isolation (Playwright component testing, Storybook)
- contract tests: services agree on their API (Pact, Part 4)
- visual and a11y checks ride on UI tests (Part 5)
Who owns what
Who writes which tests? Usually developers write unit tests, and SDETs review them for missing edge cases. API and integration tests are shared, often led by SDETs. UI journeys are mostly SDETs, with developers adding cases for their features. SDETs also own the framework, the pipeline and the reports. But the suite belongs to the whole team, and a modern SDET coaches developers to test well rather than testing everything alone.
- unit: developers, reviewed by SDETs for edge cases
- API / integration: shared; SDETs often lead
- UI journeys: SDETs, with developers adding cases
- framework, CI, reports: SDETs
- one suite, one owner: the team
Common mistakes
Shape mistakes that slow teams down. Testing every rule through the browser. Repeating the same check at three layers, so one bug fails five tests. Unit tests so full of mocks that they only test the mocks. The opposite mistake, no end to end tests at all, so nobody knows if the pieces work together. Counting tests instead of asking what bugs they catch. And ignoring how long the suite takes, until it is too late.
- every rule tested in the UI
- duplicating the same check at three layers
- unit tests full of mocks that test nothing real
- zero end-to-end tests
- counting tests instead of asking what they catch
- ignoring suite run time
Say it like this
In the interview, say: the pyramid means many fast unit tests, fewer API or integration tests, and few UI tests, because lower tests are faster, cheaper and point straight at the bug. I test each rule at the lowest layer that can catch it, and keep the browser for user journeys. Then show nuance: for UI heavy apps, the testing trophy, with more integration tests, often fits better, and I would choose based on where our bugs come from.
- "Many fast unit tests, fewer
- API or integration tests, few
- UI tests, because lower tests
- are faster, cheaper and point
- at the bug. I test each rule
- at the lowest layer that can
- catch it and keep the UI for journeys. For UI-heavy apps
- the trophy, more integration, often fits better."