IICTPIICTP

Blog / Guides

Answers3 November 20264 min read

What is the test pyramid?

The test pyramid is a rule of thumb for balancing automated tests: write many small, fast unit tests, fewer integration tests, and only a handful of slow end-to-end tests. The shape matters because tests lower down are cheaper to run and easier to diagnose.

In this post
  1. What are the three layers?
  2. Why is it a pyramid and not a rectangle?
  3. What is a flaky test, and why is it a problem?
  4. Does the pyramid mean never write end-to-end tests?
  5. How does it relate to continuous integration?
  6. Sources and further reading

What are the three layers?

  • Unit tests check one function or class in isolation and run in milliseconds.
  • Integration tests check that parts work together, for example code and a database.
  • End-to-end tests drive the whole system the way a user would, and are the slowest and most fragile.

Why is it a pyramid and not a rectangle?

Every layer you climb costs more to run, more to maintain and more to debug when it fails. A suite that is mostly end-to-end tests is slow and flaky, so people stop trusting it. Many cheap tests at the bottom give fast feedback and pinpoint failures.

What is a flaky test, and why is it a problem?

A flaky test sometimes passes and sometimes fails with no code change. It teaches the team to ignore red builds, which hides real failures. Fix it or remove it quickly, and find the cause, which is often timing, shared data or a network call.

Does the pyramid mean never write end-to-end tests?

No. Keep a few for the journeys that matter most, such as signing up and paying. The pyramid is about proportion, not about banning a layer.

How does it relate to continuous integration?

Fast tests make it practical to run checks on every change before it merges, which is the core of CI and CD. A suite that takes an hour defeats the purpose.

Sources and further reading

  1. Cohn, M. (2009). Succeeding with Agile. Addison-Wesley.
  2. Fowler, M. “TestPyramid”. martinfowler.com/bliki/TestPyramid.html.

Go deeper: CTP™ credential · the TPBOK™ standard · Check your experience

IICTP is an independent technical credentialing body.

Keep reading

← All posts

New guides in your inbox

Plain-language guides on technical practice, now and then. You confirm your address first, and you can unsubscribe at any time.

Where do you stand?

Find the credential that fits the work you do.