# What is the test pyramid? Layers, ratios and alternatives

URL: https://sdclabs.com/glossary/test-pyramid/

> The test pyramid puts many unit tests at the base, fewer integration tests above them and few end-to-end tests on top. Layers, ratios and a shape check.

# What is the test pyramid?

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) 2026-11-29

Definition

The test pyramid is a model for splitting an automated test suite by level: many fast unit tests at the base, fewer integration or API tests in the middle, and a small number of slow end-to-end tests at the top. It keeps feedback fast and limits brittle, costly UI tests.

## Where does the test pyramid come from?

Mike Cohn described the model in his 2009 book Succeeding with Agile, where it appears as the "Test Automation Pyramid", according to Martin Fowler's [Test Pyramid](https://martinfowler.com/bliki/TestPyramid.html) entry (first published in May 2012, last revised in November 2017, so an older source). In everyday use the name shrank to "test pyramid".

The argument behind the shape is about cost. In Fowler's words, tests that run end-to-end through the UI are "brittle, expensive to write, and time consuming to run." So most checks should live in fast, focused tests, with a middle layer that goes through the service layer. In a web app, that middle layer means testing through the API instead of the browser.

Fowler also gives a rule for bugs found high up. When a high-level test fails, you have two problems: a bug in the code, and a missing or wrong lower-level test. He advises reproducing the bug with a unit test before fixing it, so the unit test keeps it from coming back.

## What are the layers of the test pyramid?

The UK Home Office engineering standard [SEGAS-00017 Test pyramid](https://engineering.homeoffice.gov.uk/standards/test-pyramid/) , last updated October 31, 2025 (just over a year old), turns the layers into requirements:

| Layer | What the standard puts there | Its rule for the layer |
|---|---|---|
| Base | Unit and [contract tests](https://sdclabs.com/glossary/contract-testing/) of the smallest testable parts, in isolation | Fast to write, run and give feedback, for early bug detection |
| Middle | Component tests and component integration tests | Verify that parts work together, and stay fast to execute |
| Top | End-to-end tests of whole user flows | Only for "critical user flows and high-risk areas"; "You MUST avoid large numbers of end-to-end tests" |

The standard also requires metrics as evidence of test efficiency, and says these should be captured at a minimum: defect density, test execution time, percentage of unreliable tests, defect leakage across levels and automation coverage. It allows exceptions too. Safety-critical systems need thorough testing at every level, and for complex integrations or AI, "more end-to-end tests might be needed."

## What ratio of unit, integration and end-to-end tests should you aim for?

A ratio is a rule of thumb. Google offered one in the Testing Blog post [Just Say No to More End-to-End Tests](https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html) (April 22, 2015, an older source): "As a good first guess, Google often suggests a 70/20/10 split: 70% unit tests, 20% integration tests, and 10% end-to-end tests." The same post adds that the exact mix differs per team and names two shapes to avoid:

- **Inverted pyramid, or ice cream cone:** the team relies mostly on end-to-end tests, with few integration tests and even fewer unit tests.
- **Hourglass:** many unit tests and many end-to-end tests, but few integration tests in between, so end-to-end tests do work that smaller integration tests could do.

Treat 70/20/10 as a starting point to question, not a target to hit. A ratio of test counts says nothing about whether each test checks something that matters.

## Test pyramid vs testing trophy and honeycomb: which shape is right?

Newer shapes argue with the pyramid's base. In [On the Diverse And Fantastical Shapes of Testing](https://martinfowler.com/articles/2021-test-shapes.html) (June 2, 2021, an older source), Fowler summarizes the dispute: the honeycomb and the trophy say you should have relatively few unit tests and focus mostly on integration tests.

His answer is that much of the argument is about definitions. A "solitary" unit test replaces every collaborator with a test double; a "sociable" one lets real collaborators run. In Fowler's reading, what honeycomb advocates call integration tests sounds a lot like sociable unit tests, so both camps may be asking for similar suites. Before you compare your suite with any shape, write down what your team means by unit and integration.

## Is the test pyramid still enough?

Google's testing team has since gone further. [SMURF: Beyond the Test Pyramid](https://testing.googleblog.com/2024/10/smurf-beyond-test-pyramid.html) , published October 15, 2024 (just over two years old, an older source), says the pyramid "lacks the details you need as your test suite grows" and names five trade-offs to weigh for each test:

| Letter | Property | What it asks |
|---|---|---|
| S | Speed | How soon does this test report a problem? |
| M | Maintainability | What does debugging and updating it cost over time? |
| U | Utilization | How much memory, disk and CPU does it use per run? |
| R | Reliability | Does it fail only when something is actually broken? |
| F | Fidelity | How close are its conditions to production? |

By the post's own descriptions, unit tests are faster and usually use fewer resources, while integration and end-to-end tests can better reflect real conditions. That is one reason to keep the top of the pyramid. The post also warns that improving one property can affect the others.

This matters more now that AI agents draft tests. A generated browser test can cost little to write, so writing cost limits the top layer less. Run time, flakiness and upkeep still grow with every test, so the pyramid's reasoning still applies.

## Example: measure the shape of your suite

This script takes three numbers per layer from CI reports (test count, average duration and the chance that a test fails for no reason in a run) and prints the shape, the serial run time and how many builds go red from flaky tests alone. The "before" suite is an hourglass; "after" moves 320 end-to-end tests that only checked business rules down to API level.

# pyramid.py: what shape is the suite, how long does it run, and how often do flaky tests turn a build red? # The numbers are an example. Export yours from CI reports: test count, average duration and flake rate per layer. def shape(unit, integration, e2e): if unit >= integration >= e2e: return "pyramid" if e2e >= integration >= unit: return "ice cream cone" if integration < unit and integration < e2e: return "hourglass" return "integration-heavy" def report(name, layers): total = sum(n for n, _, _ in layers.values()) print(f"{name}: {shape(*(n for n, _, _ in layers.values()))}") clean_build = 1.0 for layer, (n, secs, flake) in layers.items(): clean_build *= (1 - flake) ** n # chance that no test in this layer fails for no reason print(f" {layer:<12}{n:>5} tests {n / total:>5.0%} {n * secs / 60:>6.1f} min") minutes = sum(n * secs for n, secs, _ in layers.values()) / 60 print(f" serial run time {minutes:.1f} min, builds red from flakes alone: {1 - clean_build:.0%}") # (tests, average seconds per test, chance that one test fails for no reason in a run) before = {"unit": (1800, 0.02, 0.00001), "integration": (120, 0.8, 0.0002), "end-to-end": (400, 20.0, 0.002)} # Same checks, but 320 end-to-end tests that only verified business rules moved down to API level after = {"unit": (1800, 0.02, 0.00001), "integration": (440, 0.8, 0.0002), "end-to-end": (80, 20.0, 0.002)} report("before", before) report("after", after)
Output with Python 3.11 (python3 pyramid.py):

before: hourglass unit 1800 tests 78% 0.6 min integration 120 tests 5% 1.6 min end-to-end 400 tests 17% 133.3 min serial run time 135.5 min, builds red from flakes alone: 57% after: pyramid unit 1800 tests 78% 0.6 min integration 440 tests 19% 5.9 min end-to-end 80 tests 3% 26.7 min serial run time 33.1 min, builds red from flakes alone: 23%
The same checks now run in a quarter of the time, and fewer builds fail for no reason. The flaky rate compounds with the test count: 400 tests that each flake 0.2% of the time turn more than half of all builds red. The remaining 23% shows that reshaping the suite does not replace fixing unreliable tests.

## How do you move a suite toward a pyramid?

1. **Classify tests by what they touch** , not by folder name: a browser, a running service, a database, or nothing outside the code.
1. **For each end-to-end test, find the assertion that needs the browser.** If none does, move the check to API or unit level. Keep [end-to-end tests](https://sdclabs.com/glossary/end-to-end-testing/) for the journeys that make money or carry risk.
1. **Pin every bug a high-level test finds with a lower-level test** before fixing it, as Fowler advises.
1. **Track run time and the share of unreliable tests per layer** , two of the metrics on the Home Office list and the two the example above uses.
1. **Keep a full run in the pipeline.** Moving checks down shortens feedback; the [regression testing](https://sdclabs.com/glossary/regression-testing/) entry covers what still needs to run before each release.

Our [QA and test automation](https://sdclabs.com/services/qa-and-test-automation/) team works out with you what to test at which level, what to automate and what to leave to exploratory testing. When end-to-end tests are flaky, we fix waits, locators and test data in the test code, and move checks to the API level where the UI adds nothing.

## Sources

1. [Test Pyramid](https://martinfowler.com/bliki/TestPyramid.html) , martinfowler.com, 2017-11-15
1. [SEGAS-00017 Test pyramid](https://engineering.homeoffice.gov.uk/standards/test-pyramid/) , UK Home Office, Engineering Guidance and Standards, 2025-10-31
1. [Just Say No to More End-to-End Tests](https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html) , Google Testing Blog, 2015-04-22
1. [On the Diverse And Fantastical Shapes of Testing](https://martinfowler.com/articles/2021-test-shapes.html) , martinfowler.com, 2021-06-02
1. [SMURF: Beyond the Test Pyramid](https://testing.googleblog.com/2024/10/smurf-beyond-test-pyramid.html) , Google Testing Blog, 2024-10-15

## Frequently asked questions

### Is the test pyramid outdated?

The reasoning still holds: broad tests are slower and fail for more reasons than focused ones. What has changed is the detail around it. Google's SMURF post adds maintainability, resource use and fidelity to the trade-off, and shapes like the trophy shift weight toward integration tests.

### Where do manual and exploratory tests fit in the test pyramid?

They sit outside it. The pyramid describes how to balance automated tests, while exploratory testing is people looking for problems nobody wrote a test for. Automation frees time for it; see our post on [manual and exploratory testing](https://sdclabs.com/blog/manual-exploratory-testing/) .

### Do contract tests belong in the test pyramid?

Yes. The UK Home Office standard places unit and contract tests together at the base, as low-level tests that run in isolation and must be fast. A [contract test](https://sdclabs.com/glossary/contract-testing/) checks the messages between two services without starting both of them.

### How do you find out what shape your test suite has?

Count tests per layer from your CI reports, grouped by what each test touches (nothing outside the code, a service, a database or a browser), and add each layer's run time and flaky share. Counts show the shape; run time and flaky share show what the shape costs you.

Services

- [QA and test automation](https://sdclabs.com/services/qa-and-test-automation/)

Read next

- [What is test automation? A guide from the founders of Codeception and CodeceptJS](https://sdclabs.com/blog/what-is-test-automation/)
- [Faster delivery needs stronger tests: QA and test automation in 2026](https://sdclabs.com/blog/qa-test-automation-challenges/)

Related terms

- [End-to-end testing](https://sdclabs.com/glossary/end-to-end-testing/)
- [Regression testing](https://sdclabs.com/glossary/regression-testing/)
- [API testing](https://sdclabs.com/glossary/api-testing/)
- [Shift-left testing](https://sdclabs.com/glossary/shift-left-testing/)

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) Chief Operating Officer14+ years in QA, automated, exploratory and performance testing, and continuous integration and delivery within Scrum, helping teams in product and outsourcing companies organize teams, processes and tools.[LinkedIn](https://www.linkedin.com/in/sergeyalmyashev/)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
