Bookmarks

Test pyramid

A model that distributes automated tests across levels: many fast unit tests at the bottom, fewer integration tests in the middle, and a few slow end-to-end tests at the top.

Also: testing pyramid, automated test pyramid

checked 9 Nov

All terms

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

LevelWhat it checksSpeed and share
Unit teststhe logic of one class or function, with dependencies replaced by test doublesmilliseconds; the largest number of tests
Integration testshow modules work together: API, database, message queueseconds; noticeably fewer than unit tests
End-to-end testsa user’s path through the built interface and all servicesminutes; 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

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • E2Eend-to-end test

    An end-to-end test is one level of the pyramid, its top. The pyramid itself says how many tests to keep at each level.

  • code coverage

    Code coverage measures what share of the code the tests execute. The pyramid describes the levels at which those tests sit.

In depth in the references

where the topic is covered in detail