All articles
165 articles · updated weekly See our Tools
All articles
Tips

Testing pyramid: what it is, its layers and the ice cream cone

The testing pyramid: its three layers (unit, integration, e2e), the ice cream cone anti-pattern, and modern alternatives like the trophy, honeycomb and diamond.

Testing pyramid: what it is, its layers and the ice cream cone
COVER · Tips

The testing pyramid is a model that organizes automated tests into three layers — many unit tests at the base, fewer integration tests in the middle, and few end-to-end (e2e) tests at the top. The logic is economic: the higher a test sits in the pyramid, the slower, more expensive, and more brittle it is, so verification should live at the lowest layer that still gives you confidence.

In practice, people usually arrive at this concept through pain. Your suite takes 40 minutes to run, fails randomly on half of your pull requests, and yet an obvious bug slipped into production last week. The team has thousands of tests — but most are slow, flaky e2e tests opening an entire browser to check a business rule that would fit in three lines of a unit test. That has a name: the upside-down pyramid, the ice cream cone.

This post covers the original model, the anti-pattern, the alternative shapes that came later (trophy, honeycomb, diamond, crab), and how to calibrate the proportions without becoming a hostage to a drawing.

The three layers of the testing pyramid

Mike Cohn popularized the pyramid in 2009 in Succeeding with Agile. The layers differ in cost, speed, and how much of the system each test exercises:

  • Wide base — unit tests. Verify a single unit of code (function, method, class) in isolation. They run in milliseconds, are cheap to write, and when they fail they point to a specific place. They should be the majority.
  • Middle — integration tests. Verify that parts of the system talk to each other correctly: the repository with the database, the HTTP handler with the service, the consumer with the queue. Slower, with more setup.
  • Narrow top — end-to-end (e2e) tests. Simulate a real user crossing the whole system, usually through the browser. They're the closest to production and also the slowest and most brittle. There should be few.

The core message is not "write exactly 70% unit, 20% integration, 10% e2e" — fixed percentages are a convention, not part of the model. The message is: push each check down to the lowest layer that still gives you confidence. A failing unit test points at a function; a failing e2e could be the network, timing, a CSS selector, or an actual bug, and you burn time investigating before you know which.

The difference between the two bottom layers deserves its own post — and has one: unit test vs integration test shows, with API and database examples, what each one catches and what it lets through. Here the focus is the shape of the whole suite.

The ice cream cone anti-pattern

The ice cream cone is the inverted pyramid: lots of manual and e2e testing at the top, some integration tests in the middle, and almost no unit tests at the base. It's the 40-minute scenario from the opening.

It's usually born from good intentions. The team wants to "test the way users use it," starts automating what QA used to do by hand in the browser, and every new bug becomes another e2e. The symptoms show up together:

  • Slow suite: feedback arrives after the developer has already switched context.
  • Flakiness: tests that fail with no code change, due to timing, network, or shared data. The team starts re-running until green, and the suite stops meaning anything.
  • Expensive diagnosis: a red e2e tells you something broke, not what.
  • Illusory rule coverage: each business rule is checked through one path only, the happy one, because writing five e2e tests for five discount variations isn't viable.

The fix isn't deleting the e2e tests all at once. It's moving checks down: each rule that today is only verified in the browser gets a unit or integration test, and the corresponding e2e becomes redundant and can go. web.dev also mentions the crab, a close variation of the cone with emphasis on e2e and visual tests — useful for applications where appearance is the product, but with the same costs.

Pyramid, trophy, honeycomb, diamond, and crab

The pyramid was born in a world of monolithic applications. In modern architectures, part of the logic lives at the boundary between components, and alternative shapes emerged. web.dev's article Pyramid or Crab? Find a testing strategy that fits collects the main ones:

  • Testing trophy — from Kent C. Dodds, in the front-end JavaScript context. The base is static analysis (TypeScript, ESLint), the largest body is integration tests, and unit and e2e shrink. The argument: in a React or Svelte UI, testing an isolated component with everything mocked gives little confidence and breaks on every refactor. The motto comes from a Guillermo Rauch line Dodds adopted: "Write tests. Not too many. Mostly integration."
  • Testing honeycomb — from Spotify's engineering team, for microservices. The focus is integration tests for each service, with few tests of implementation details and few tests that depend on other systems. In a microservice, the value is in verifying interaction, not the unit.
  • Diamond — the pyramid with the unit base cut: integration at the center, unit tests only for the most critical cases (because they tend to break during refactors), and e2e also limited.
  • Crab — described in the previous section: close to the cone, with e2e and visual tests in focus.

Martin Fowler, in On the Diverse And Fantastical Shapes of Testing (2021), notes that much of the fight between shapes is a fight over definitions. What the pyramid's critics call an "integration test" is often what he calls a sociable unit test — one that uses real collaborators instead of test doubles. With that translation, the shapes contradict each other far less. The line of his I quote most: debating what percentage of each test type to write is a distraction; the bigger problem is that few teams write expressive tests.

The testing pyramid on the front-end

The trophy gained traction precisely on the front-end, for a concrete reason: a UI component is rarely pure logic. A button that triggers a search involves state, effects, a network call, and rendering. Testing it with everything mocked verifies that you configured the mocks, not that the screen works.

In practice, a healthy front-end suite usually has:

  • Static analysis as the first layer: strict TypeScript and ESLint catch a whole class of errors without running anything.
  • Unit tests for pure functions: formatting, validation, calculations, reducers.
  • Component integration tests as the bulk: render the component with its real children (Testing Library, Vitest) and mock only the network boundary.
  • A few e2e tests (Playwright, Cypress) for the flows that make money: login, checkout, sign-up.
// Instead of a unit test checking that "id" isn't undefined,
// the type already guarantees it at compile time (strictNullChecks):
function getUser(id: string): User { /* ... */ }
getUser(undefined); // compile error — bug caught for free

What really changed: the middle got heavier

The common thread across the critiques is that the integration layer became more valuable than the classic pyramid suggested:

  1. Front-ends depend on the back-end. Testing isolated components with heavy mocks tests the mock, not the system.
  2. Microservices push bugs to the boundaries. The unit can be perfect while the system breaks on the contract between services — that's the territory of contract testing between services.
  3. Excessive test doubles create false confidence. If you mock everything, the test passes even when reality has shifted. The post on mocks, stubs, and fakes separates when each double helps and when it hurts.

This doesn't kill the pyramid — it shifts the balance. The unit base is still where you cover dense business logic (calculations, validations, conditional rules), the kind of thing Unit testing: what to test goes into.

How to balance it in practice

Forget memorized percentages. Use these heuristics:

Push verification down until it hurts. If the rule fits in a unit test, don't write an e2e for it. Reserve e2e for critical business flows — the post on when e2e tests are worth it helps pick which. For APIs, the middle layer is where the payoff is; see how to test APIs in an automated way.

Treat static analysis as a test layer. Strict TypeScript, a linter, and schema validation eliminate entire bug classes before any test runs. It's the cheapest rung.

Measure what hurts, not the count. Total suite time, flakiness rate, and average time to find the cause of a failure say more than the number of tests. 100% coverage with a flaky suite is worse than a reliable 70%.

Quarantine flaky tests instead of retrying them. An e2e that needs three retries doesn't give confidence, it gives noise. Isolate it, fix it, or delete it.

Symptom                          → Likely imbalance
Slow + flaky suite               → ice cream cone (too much e2e)
Refactor breaks 50 tests         → units coupled to implementation
Integration bug slipped through  → anemic middle (integration)

Frequently asked questions

Is the testing pyramid outdated?

Not as a concept; yes as a dogma of percentages. The economic intuition — higher tests are slower and more brittle — holds in any stack. What aged is the rigid proportion: architectures with lots of logic at the boundaries justify a fatter integration layer than the classic pyramid draws. Use it as a compass, not a map.

What's the difference between the testing pyramid and the testing trophy?

The pyramid puts unit tests as the wide base. Kent C. Dodds's trophy puts static analysis at the base, integration as the largest layer, and shrinks unit and e2e. It was born in front-end JavaScript, where testing isolated components with many mocks gives little confidence. For microservices, the most cited shape is Spotify's honeycomb.

What's the right ratio of unit, integration, and e2e tests?

There's no universal ratio; fixed percentages like 70/20/10 are a convention, not a rule. Decide by risk: where domain logic is dense (calculations, conditional rules, validations), unit tests pay off more and the classic pyramid describes the suite well; where behavior lives at the boundaries (CRUD APIs, database, queues, microservices), integration tests pay off more and the suite tends toward the honeycomb — it's common for an API back-end to have as many integration tests as unit tests, or more. Either way, e2e tests stay few and reserved for critical flows.

How many e2e tests should I have?

Few and deliberate. Cover the flows where a failure costs money or reputation — authentication, payment, critical sign-up. Anything that can be verified lower down (business rule, validation, formatting) should leave the e2e layer. If your e2e count keeps growing, there's probably logic that should be covered by unit or integration tests.

Use any drawing you like, as long as the principle survives

The testing pyramid isn't a law of physics — it's a mental model about the trade-off between cost, speed, and confidence. That trade-off hasn't changed: tests at the top are still slow and brittle. What changed is the context, which pushed weight toward integration and static analysis. Pyramid, trophy, honeycomb, or diamond: cover each risk at the cheapest layer that still gives you confidence, and distrust any suite that's slow, flaky, and still lets bugs through.

One thing that helps a lot when moving tests down a layer is test data that's easy to generate. When I need realistic fixtures for an integration test — a list of users or orders with varied fields — I generate the JSON with the JSON Mock Data Generator and commit it next to the test, instead of building it by hand or depending on a shared database.

RD
Author
Rafael Duarte
Backend developer with a background in fintech and B2B SaaS — worked on teams that scaled APIs from zero to millions of requests. Carries enough production scars to hold strong opinions on tools, patterns and architecture decisions. Not an academic: he read the UUID RFC when he had to choose between v4 and v7 for a write-heavy table.
View profile