The test pyramid answers the question of how many tests of each level a project should have. The closer a test is to the top, the slower it is, the more it costs to maintain and the less reliable it is: end-to-end checks involve the whole interface and backend, so they break over small things. Hence the shape: a wide base of unit tests and only a handful of checks through the interface.
Levels of the pyramid
| Level | What it checks | Speed and share |
|---|---|---|
| Unit tests | the logic of one class or function, with dependencies replaced by test doubles | milliseconds; the largest number of tests |
| Integration tests | how modules work together: API, database, message queue | seconds; noticeably fewer than unit tests |
| End-to-end tests | a user’s path through the built interface and all services | minutes; a handful of key scenarios |
The names of the layers are not important: in Cohn’s version the middle level is called the service level, where the application is tested through its services, bypassing the interface. The shape is what matters. If it is turned upside down and most tests are end-to-end, the suite becomes slow and brittle, and failures point to the whole stack rather than to the defect. In Ham Vocke’s article on martinfowler.com this profile is called the “ice-cream cone”: an inverted pyramid with a scoop of ice cream on top.
Why it matters
- Precise diagnosis: a failing unit test points to a specific class or line, not to “something broke in the database query”.
- Fast feedback: the unit suite runs on every build, so a problem shows up within minutes.
- Stability: the lower levels have fewer external dependencies and fewer flaky tests.
- Cheap maintenance: fixing a failing unit test is easier than fixing an end-to-end scenario.
Where the term comes from
The model was proposed by Mike Cohn in the book “Succeeding with Agile: Software Development Using Scrum” (2009). Ham Vocke later analysed it in the article “The Practical Test Pyramid” on martinfowler.com and stated its main principle: the higher the level, the fewer tests there should be.
Sources
the term is written from these pages- Mike Cohn — The Forgotten Layer of the Test Automation Pyramidmountaingoatsoftware.com/blog/the-forgotten-layer-of-the-test-automation-pyramid(opens in a new tab)
- Mike Cohn — Succeeding with Agile: Software Development Using Scrum (Addison-Wesley, 2009)mountaingoatsoftware.com/books/succeeding-with-agile-software-development-using-scrum(opens in a new tab)
- Ham Vocke — The Practical Test Pyramid (martinfowler.com)martinfowler.com/articles/practical-test-pyramid.html(opens in a new tab)
Verified 9 Nov