Skip to content
Figure 1The test automation pyramid: many unit tests, fewer service tests, few UI tests
The test automation pyramid: many unit tests, fewer service tests, few UI testsUI / end-to-end5 to 10 percentService / API / integration20 to 30 percentUnit60 to 70 percentcost per test and run time rise towards the top
The pyramid as a starting shape. Width is test count; height is cost per test and run time. The percentages are a default, adjusted per system below.

Test automation pyramid: ratios, costs and when to break it

The test automation pyramid is a budgeting device for automated checks. It says most automated checks should run in milliseconds against code, fewer should run in seconds against services, and only a handful should drive a browser or device. Used as a starting ratio it prevents the most expensive mistake in automation. Used as dogma it produces the wrong suite for data-heavy and UI-heavy systems.

Quick answer

Start at roughly 70 percent unit, 20 percent service or API and 10 percent UI tests by count. Unit tests take minutes to write and milliseconds to run; UI tests take hours to write, minutes to run, and fail for reasons unrelated to the product. Invert the shape and the suite becomes an ice cream cone: slow, brittle, distrusted.

Key figures

Starting ratio
70 / 20 / 10
Unit test run time
1 to 50 ms each
API test run time
50 ms to 2 s each
UI test run time
5 to 60 s each
Cost to write, UI vs unit
roughly 10x
Cone warning sign
UI tests over 30 percent of suite

What the shape is actually saying

Three claims sit inside the pyramid. First, tests closer to the code are cheaper to write, faster to run and more precise about what broke. Second, tests farther from the code catch a class of defect the lower layers cannot: integration mistakes, configuration, the wiring between components. Third, because the upper layers are more expensive and less precise, you want as few of them as still catches that class. The shape follows from the three claims. It is not an aesthetic preference and not a rule about percentages, which is why the numbers below are called a starting point.

A useful reframing: every behavior should be checked at the lowest layer that can observe it. A rounding rule belongs in a unit test. A permission check across two services belongs in an API test. Whether the checkout button is visible after login belongs in a UI test, and there should be exactly one of those, not forty.

Layer ratios and what each costs

Cost and run time by layer. Ranges are what mature teams report; measure your own and replace them.
LayerShare by countTypical run time per testCost to write and maintainWhat it catches
Unit60 to 70 percent1 to 50 millisecondsMinutes; near zero maintenance when code is stableLogic errors, boundary mistakes, regressions in a single class or function
Component5 to 10 percent50 to 500 millisecondsTens of minutes; low maintenanceWiring inside one deployable, database mapping, serialization
Service / API / contract15 to 20 percent50 milliseconds to 2 secondsAbout an hour; moderate maintenance when schemas changeIntegration between services, authorization, error handling, contract drift
UI / end-to-end5 to 10 percent5 to 60 secondsSeveral hours; high maintenance, most flakyBroken user journeys, environment and configuration faults, deployment errors
Manual and exploratoryNot counted in the pyramidHuman pacedSession time onlyUsability problems, missing requirements, surprises no script anticipated

The cost column is the one to argue from. A UI test that takes 4 hours to write and 30 minutes a month to keep alive costs the same as roughly 10 API tests or 50 unit tests over a year. If the same defect could have been caught lower down, that UI test is displacing 50 checks that would have run in the time it takes to start a browser.

The 70/20/10 starting point and how to adjust it

Start at 70 percent unit, 20 percent service, 10 percent UI by count, then move the boundaries using two observations from your own data. If most escaped defects in the last two quarters were integration faults (wrong status code, broken message format, permission misapplied), grow the API layer toward 30 percent and shrink unit. If most escapes were logic errors inside a component, the unit layer is under-built and the fix is coverage there, not more UI tests. Look at where coverage is thin per layer rather than in aggregate; a system can report 80 percent line coverage and have no test that crosses a service boundary.

Count by execution time too. A healthy suite spends about half its wall-clock time in UI tests even though they are a tenth of the count. If UI tests consume 90 percent of run time, they are also consuming 90 percent of your maintenance and the ratio by count is misleading you.

The ice cream cone: how suites invert

Figure 2The inverted pyramid: the ice cream cone anti-pattern
The inverted pyramid: the ice cream cone anti-patternUI / end-to-end60 to 70 percentService / API / integration20 to 30 percentUnit5 to 10 percentinverted: slow, brittle UI checks carry the load
Inverted shape: many UI tests, a thin API layer, few unit tests, and a large manual regression on top. Slow, brittle, and the first thing switched off under deadline.

Nobody designs the cone. It grows when a testing team, given a browser automation framework and no access to the code, automates the manual regression suite screen by screen. Two years later there are 1,200 UI tests, a 6 hour run, a 15 percent flaky rate and developers who merge without waiting for the result. The tell-tale signs, in the order they appear: UI tests exceed 30 percent of the suite, the nightly run is the only run, a rerun-on-failure step is added to the pipeline, and a quarantine list grows without a limit.

Recovery is not deletion. Take each UI scenario and ask what it is really checking. Push the data and logic assertions down into API and unit tests, keep one UI test per critical journey, and delete the rest once the lower tests are green. Teams that do this typically cut UI count by 70 to 80 percent while keeping defect detection flat.

When the pyramid is the wrong shape

The pyramid assumes the risk is in the logic. Two kinds of systems break that assumption.

  • Data-heavy systems (reporting, pipelines, billing runs). The risk is in the data flowing between stages, not in any one function. The right shape is a wide integration layer: many tests that push known input through the real pipeline and compare output to a golden set, with a thin unit layer for transformations and almost no UI. Some teams call this a diamond.
  • UI-heavy products (design tools, editors, anything where the interface is the product). Logic is thin and the behavior users care about lives in rendering and interaction. Component tests that mount one UI component in isolation take the place of unit tests, and the UI layer legitimately grows to 20 or 30 percent.
  • Thin front ends over third-party services. Little owned logic, heavy integration risk. Contract tests against each external dependency carry the suite; unit tests are few because there is little to unit test.

The honeycomb or trophy variants you will see described elsewhere make the same point generically: for a system built mostly from integration, the middle layer is where most tests belong, with a small unit base and a small end-to-end top. Pick the shape from your defect history, then defend it with the same cost table.

Test lead's check

Pull the last 30 escaped defects and tag each with the lowest layer that could have caught it. The distribution of those tags is the pyramid your system actually needs.

Making the ratio stick

A ratio survives only if something enforces it. Add three checks to the definition of done: every new behavior has a test at the lowest layer that can observe it, every new UI test is justified by a journey not already covered, and UI test count is reported per sprint. Put the per-layer counts and run times on the same dashboard as pass rate. When the UI layer grows faster than the API layer for two sprints running, the automation strategy needs a conversation, not another test.

Common questions

Is 70/20/10 a rule?

No. It is a default that is wrong in a predictable direction for data-heavy systems (too few integration tests) and UI-heavy products (too few UI and component tests). Use it for the first quarter, then rebalance from escaped-defect data.

Where do contract tests sit in the pyramid?

In the service layer, and they let you shrink the end-to-end layer. A consumer-driven contract test verifies that a provider still honors what its consumers expect, which replaces the multi-service end-to-end test that used to check the same thing in 40 seconds.

Do manual tests belong in the pyramid?

Not in the ratio. Exploratory and usability sessions sit alongside it as a separate, deliberately unscripted activity. Drawing them as a cloud above the pyramid reminds people they still happen; counting them in the percentages hides that they are not automated.

How many end-to-end tests are too many?

More than one per critical user journey is usually too many. A mid-sized web product has 15 to 40 critical journeys. If you have 300 end-to-end tests, at least 250 of them are checking something an API test could check in a fiftieth of the time.

Our developers write few unit tests. Should testers write them?

Testers can pair, review and coach, but unit tests written by people who do not own the code go stale immediately. Fix the incentive instead: unit coverage on changed code as a pull request check, and a definition of done that names it.

What is the difference between the pyramid and the ice cream cone?

Same layers, opposite proportions. The cone has many UI tests, few unit tests and a thick manual regression layer on top. It arises from automating manual scripts as they stand, and it is recognizable by a slow nightly run that nobody trusts.

Sources

  1. Ham Vocke, The Practical Test Pyramid (martinfowler.com)
  2. Martin Fowler, Test Pyramid
  3. Mike Cohn, The Forgotten Layer of the Test Automation Pyramid

Further reading named in the text

  • Mike Cohn, Succeeding with Agile: Software Development Using Scrum (Addison-Wesley, 2009)
  • Lisa Crispin and Janet Gregory, Agile Testing: A Practical Guide for Testers and Agile Teams (Addison-Wesley, 2009)
  • Gerard Meszaros, xUnit Test Patterns: Refactoring Test Code (Addison-Wesley, 2007)
  • Jez Humble and David Farley, Continuous Delivery (Addison-Wesley, 2010)
  • ISTQB Certified Tester Foundation Level Syllabus, version 4.0 (ISTQB, 2023)

This guide is part of the test automation hub. It is best read alongside test automation strategy and continuous testing, which cover the neighbouring questions.