Test Pyramid
- In Turkish
- Test Piramidi
In short
The test pyramid is a model for balancing automated tests: many fast unit tests, fewer integration tests, and only a few slow end-to-end tests at the top.
What is the test pyramid?
The test pyramid is a guideline for how to shape an automated test suite. It recommends a wide base of unit tests, a smaller middle layer of integration tests, and a narrow top of end-to-end tests. Mike Cohn popularized the idea in his 2009 book Succeeding with Agile, and it remains one of the most common ways teams discuss test strategy.
The shape follows a trade-off. Tests near the bottom are fast, cheap to write, and point to the exact line that broke, while tests near the top are slow, need a full environment, and are more likely to become flaky, but give more confidence that the whole system works. The practical rule is to push each test as low as it can go: if a unit test can catch a bug, don't write an end-to-end test for it, and keep the top layer for a handful of critical flows such as login and checkout.
It works like a food pyramid: plenty of staples at the bottom and only a little dessert at the top, because every layer has a role but the proportions matter. The opposite shape, sometimes called the ice cream cone, has mostly manual and end-to-end tests with few unit tests, which leads to slow, fragile pipelines. Some teams prefer alternative shapes, such as the testing trophy, which puts more weight on integration tests for frontend code.
The test pyramid is a rule of thumb about proportions and speed, not a fixed ratio such as 70/20/10, and it doesn't say that end-to-end tests are bad. It is also different from test coverage: coverage measures how much code the tests execute, while the pyramid describes how the tests are distributed across levels. A perfectly shaped suite can still leave important code untested.
Key takeaways
- Write many unit tests, fewer integration tests, and only a few end-to-end tests.
- Tests higher up are slower and more fragile but test more of the system at once.
- Push each test to the lowest level that can catch the bug.
- The inverted shape, often called the ice cream cone, is a common anti-pattern.
- It is a guideline about balance, not a fixed ratio.
Example
/\
/ \ End-to-end: few, slow, most realistic
/----\
/ \ Integration: some, real databases and APIs
/--------\
/ \ Unit: many, fast, isolated, cheap to run
/------------\Readers ask
Who created the test pyramid?
Mike Cohn described the test automation pyramid in his 2009 book Succeeding with Agile. It was later refined and popularized by other practitioners, including Martin Fowler's writing on the practical test pyramid.
What is the testing ice cream cone?
It is the upside-down pyramid: a suite dominated by manual and end-to-end tests with very few unit tests. It is considered an anti-pattern because such suites are slow, expensive to maintain, and often flaky.
Is the test pyramid still relevant?
Yes, as a way of thinking about cost and speed. Teams adapt the exact shape to their system, for example writing more integration tests for thin services whose main job is talking to a database.
See also
- Unit TestTesting & Quality, p. 35A unit test is a small, automated check that verifies one function, method, or class behaves correctly in isolation from the rest of the program.
- Integration TestTesting & Quality, p. 12An integration test is an automated test that checks whether several parts of a system, such as code, a database, and an API, work correctly together.
- End-to-End TestTesting & Quality, p. 8An end-to-end test is an automated test that runs a complete user journey through the whole application, from the user interface to the database and back.
- Flaky TestTesting & Quality, p. 10A flaky test is an automated test that sometimes passes and sometimes fails without any change to the code, which makes its results hard to trust.
- Test CoverageTesting & Quality, p. 30Test coverage is a metric that measures how much of a program's source code is executed when its automated tests run, usually shown as a percentage.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
- Test AutomationTesting & Quality, p. 28Test automation is using code to run tests and check their results, so the same checks repeat quickly and consistently on every change instead of by hand.
Spotted a mistake or something missing on this page?Suggest an edit