The Testing Pyramid: Balancing Unit, Integration and E2E Tests in 2026
In this article
The Quick Answer
The testing pyramid is a model for distributing automated tests: many small, fast tests at the base, fewer broader tests in the middle, and a thin layer of slow end-to-end tests at the top. The shape follows from one fact - the higher a test sits, the more it costs to run and maintain, and the less precisely a failure tells you what broke.
The core rule: test each behavior at the lowest layer that can genuinely catch the failure you care about. Push a check up the pyramid only when the lower layer cannot see the problem.
What it is not: a quota. A healthy suite ends up roughly pyramid-shaped because teams keep making that decision well, not because someone set a target of 70 percent unit tests.
This article covers where the model comes from, what each layer costs, the anti-patterns and alternatives, and how to audit and rebalance a suite you already have. It does not teach how to write unit tests - for that, see our guide to writing unit tests.
Where the Testing Pyramid Comes From
The pyramid was popularized by Mike Cohn in his 2009 book Succeeding with Agile. Cohn's version had three layers: unit tests at the base, service tests in the middle, and user interface tests at the top. The idea was already circulating in agile teams before the book, and it spread further once Martin Fowler wrote it up on his site in 2012.
Two details of the original are worth recovering, because they have been lost in most retellings.
- The middle layer was about services, not "integration". Cohn called it the forgotten layer: tests that exercise the application through its service boundary, below the UI, so business behavior can be checked without driving a browser.
- The argument was about the UI layer. Cohn's target was automating almost everything through the user interface, where tests were slow, brittle and expensive. The pyramid corrected that habit; it was not a claim about ideal proportions.
The model has no percentages in its original form. The widely quoted 70/20/10 split came later - a 2015 post on the Google Testing Blog offered it as a reasonable first guess - and it has since been repeated so often that many teams treat it as part of the definition. It is not, and the difference matters once you try to apply it.
Modern retellings label the layers unit, integration and end-to-end. The names are loose; what defines a layer is scope and cost.
What Each Layer Is For and What It Costs
Each layer answers a different question. The mistake is expecting any single layer to answer all of them.
| Unit | Integration / service | End-to-end | |
|---|---|---|---|
| Question it answers | Does this logic do what I intended? | Do these real pieces work together? | Can a user complete this journey? |
| Scope | A function, class or small module | A service with its database, queue or framework | The deployed system, through the UI or public API |
| Typical runtime | Milliseconds | Tens of milliseconds to seconds | Seconds to minutes |
| Failure precision | Points at a line | Points at a boundary | Points at a journey |
| Main cost | Coupling to implementation if written badly | Environment and data setup | Flakiness, maintenance, infrastructure |
| Blind spot | Anything outside the unit - config, wiring, real dependencies | Cross-service journeys and real UI behavior | Edge cases, because each one is too expensive to cover |
The runtime column understates the costs. An end-to-end test needs a deployed environment, seeded data and working third parties. When it fails, someone has to decide whether the product broke, the test broke or the environment wobbled. That triage is the real cost, and it is why top-heavy suites develop flaky tests and lose the team's trust.
Unit tests have the opposite profile: cheap and precise, but they only see what you let them see. A payment calculation can be perfectly unit tested and still fail in production because the currency config was never loaded. No number of extra unit tests will catch that.
The trade in one line: moving down the pyramid buys speed and precision; moving up buys realism. Every test is a decision about which of those this particular risk needs.
Why the Ratios Are an Outcome, Not a Target
Set a ratio as a target and teams will hit it in the least useful way. Unit test counts rise because unit tests are easiest to add, while the one integration test that would have caught last month's outage never gets written, because the ratio says there are enough.
The shape that matters comes from applying the core rule case by case:
- Logic-heavy code - pricing, tax, eligibility, parsing, state machines - naturally produces lots of unit tests, because the risks are combinatorial and live inside the code.
- Glue-heavy code - a CRUD service that mostly maps HTTP to SQL - produces relatively few meaningful unit tests. Its risks live at the boundaries, and an honest suite for it will be integration-heavy.
- Journey-critical flows - sign-up, checkout, the one report customers pay for - justify a handful of end-to-end tests each, however small the rest of the suite.
So two healthy codebases can have very different ratios. A rules engine might sit near 90 percent unit tests; a thin API over a database might be half integration tests and be perfectly well tested. Counting also misleads because tests are not equal units: one broad integration test can cover what twenty narrow unit tests do.
Measure feedback time and failure precision per layer instead. If the fast layers run in under five minutes and catch most regressions before merge, and the slow layer is small enough that every failure gets investigated, the proportions are fine.
The Anti-Patterns: Ice Cream Cone, Hourglass and Cupcake
Most suites that go wrong go wrong in one of three recognizable shapes. Naming them helps, because each has a different cause and a different fix.
The ice cream cone
The inverted pyramid: a large layer of UI automation, a thin layer of unit and integration tests beneath it, and often a scoop of manual regression on top. It usually forms when automation belongs to a separate QA team with no access to the code, which can only automate what it can see - the UI. The suite takes an hour, fails intermittently, and reports "checkout test failed" without saying why. The fix is structural: developers own the lower layers, and UI tests are written only for what cannot be checked lower down.
The hourglass
Plenty of unit tests, plenty of end-to-end tests, almost nothing in between - usually because integration tests need real infrastructure and nobody set it up. The symptom is defects that pass every unit test and are only caught by a slow end-to-end run: database mappings, serialization, framework config, auth wiring. The fix is investing in the middle layer.
The cupcake
Every layer is well populated, and they all test the same things. Developers unit test the discount rule, automation engineers test it through the API, another team tests it through the UI, and manual testers check it again before release. The organization pays four times for one piece of confidence and still has gaps nobody owns. The cause is siloed teams who cannot see each other's suites; the fix is a shared view of what each layer already covers.
Quick diagnostic: if your slowest suite catches most of your regressions, you have a cone or an hourglass. If the same defect regularly fails tests in three layers at once, you have a cupcake.
The Alternatives: Testing Trophy and Honeycomb
The pyramid has two well-known challengers. Both are less a rejection of it than a correction for particular kinds of system.
The testing trophy comes from Kent C. Dodds, who built it on Guillermo Rauch's line "Write tests. Not too many. Mostly integration." It has four layers: static analysis at the base (type checking and linting), a modest unit layer, a large integration layer, and a small end-to-end cap. It came out of front-end JavaScript, where many "unit" tests render a component with every child mocked and end up testing the mocks. Dodds argues that tests rendering components together, the way a user would use them, give more confidence per test. The static layer is a fair point the pyramid ignores: a type checker removes a whole class of tests.
The testing honeycomb was described by Spotify's engineering team for microservices. It has a small layer of implementation-detail tests at the bottom, a large layer of integration tests in the middle that check a service through its real interfaces, and a small layer of integrated tests at the top that need other services running. The reasoning is that most microservices contain little logic of their own, so their risk sits in how they talk to databases and to each other.
| Model | Widest layer | Best fit |
|---|---|---|
| Pyramid | Unit | Logic-heavy code, monoliths, libraries, domain models |
| Trophy | Integration | Front-end applications and component-based UIs |
| Honeycomb | Integration | Small microservices with thin business logic |
All three agree the top layer stays thin and each check should run as low as it can while still catching the real failure. They disagree only about where that lands for a given kind of code - the pyramid's principle survives even where its shape does not.
Where Contract, Manual and Exploratory Testing Fit
The pyramid models automated tests. Three kinds of testing sit awkwardly on it.
Contract tests sit in the middle layer and replace a specific slice of end-to-end testing: the checks that two services still agree on their interface. They run at unit-test speed in each team's own pipeline - see our guide to contract testing for how that works.
Manual regression mostly should not be on the pyramid in the long run. A manual script repeated unchanged every release is an automation candidate, usually below the UI. The exception is checks that are hard to automate or rarely run - a hardware integration, a print layout, a yearly compliance export - where a maintained manual case is cheaper than a brittle script.
Exploratory testing is not a layer. Its job is finding the risks nobody thought to specify, which by definition no automated test checks. Some teams draw it as a cloud above the pyramid, which is a fair picture, and it pays off most once automation has absorbed the repetitive checking - see our exploratory testing guide. Every significant exploratory finding should raise the question of which automated layer should have caught it.
How to Audit Your Current Suite
Before changing anything, find out what shape you actually have. For most teams this takes a day or two.
- Inventory by layer. Count tests per layer, but also record total runtime and pipeline stage for each. Runtime is a better measure of weight than count.
- Pull the failure history. For the last two or three months, classify every failure per layer: real defect, test defect, environment or data, flaky. A layer where most failures are not real defects costs more than it returns.
- Trace recent escapes. For each of the last ten production defects, ask which layer could most cheaply have caught it. The answers show where coverage is missing.
- Sample for duplication. Pick five important behaviors and find every test that checks each of them. More than two layers testing the same rule is a cupcake.
- Include the manual suite. List the manual regression cases, how long a cycle takes, and which of them have found a defect in the last year.
The output is a one-page picture: runtime and signal-to-noise per layer, the gaps the escapes revealed, and the duplication you found. Having automated and manual results in one place with reporting per suite saves rebuilding it from CI logs and spreadsheets each time.
Not worth doing: auditing a young codebase with a few hundred tests and a ten-minute pipeline. If feedback is fast and failures are trusted, the shape is working. Come back when either stops being true.
Rebalancing Step by Step
Rebalancing is gradual work, done alongside feature delivery. A suite rewrite is almost never justified and almost never finished.
1. Stop the growth at the top first. A new end-to-end test needs one sentence explaining why the risk cannot be caught lower. This alone changes the trend within a quarter.
2. Quarantine or delete the noisiest top-layer tests. Tests that fail more from flakiness than from defects are harmful. Fix the few guarding critical journeys; delete the rest and note what they covered.
3. Build the middle layer if it is missing. Usually the highest-value investment. Run real dependencies in containers and make it cheap to write a test that calls an endpoint and checks the database. Until this exists, teams will keep writing end-to-end tests by default.
4. Push tests down, one journey at a time. List the assertions each end-to-end test makes. Move rules and calculations to unit tests, service behavior to integration tests, and keep one end-to-end test proving the journey connects. A 40-step UI test often becomes six unit tests, three integration tests and one short end-to-end path.
5. Remove duplicates deliberately. Where one rule is tested in three layers, keep the lowest that genuinely catches it and delete the others.
6. Re-measure every quarter. Runtime per layer, flaky rate, and the layer each escaped defect should have been caught in. Those numbers tell you whether the rebalance is working; test-count ratios do not. General suite hygiene is covered in our test automation best practices.
Common Mistakes
- Treating 70/20/10 as the definition. It is a heuristic someone offered as a starting guess, not the model.
- Measuring shape by test count. Runtime and failure signal per layer say far more than how many tests each layer holds.
- Unit tests that mock everything. They inflate the base while testing the mocks, and they break on every refactor.
- Skipping the middle layer. Without service-level tests, every boundary defect waits for the slowest suite.
- Pushing down without deleting. The new lower test is added, the old end-to-end test stays, and the suite only gets slower.
- Forcing the pyramid onto a thin service. If the code is mostly wiring, an integration-heavy suite is the right answer.
- Leaving manual and exploratory testing out of the picture. They are part of the cost and coverage whether the diagram shows them or not.
Conclusion
The testing pyramid has lasted because its central idea is correct. Tests get slower, costlier and less precise as they include more of the system, so each check belongs at the lowest layer that can really catch the failure. The trophy and the honeycomb do not overturn that; they point out that for front-end code and thin microservices, the lowest useful layer is often integration rather than unit.
What breaks teams is treating the shape as a target. Quotas get met with cheap tests that catch nothing while the expensive gaps stay open. The shape that matters emerges when every test is a deliberate decision, and the evidence it is working is fast feedback and failures people trust.
If your suite is already a cone, an hourglass or a cupcake, the fix is gradual: stop adding to the top, build the middle, push checks down one journey at a time, and delete what you replace.
That kind of rebalance is much easier to steer when every layer's results sit side by side. QA Sphere brings automated runs from CI and manual and exploratory results into one place, with reporting that shows each layer's pass rate and trend alongside your versioned test cases, and a test run builder for the manual checks that remain. See pricing or book a demo.
Written by
QA Sphere TeamThe QA Sphere team shares insights on software testing, quality assurance best practices, and test management strategies drawn from years of industry experience.



