Skip to content
Latchkey

What Is the Testing Pyramid?

The testing pyramid is a guideline for balancing test types: many fast unit tests at the base, fewer integration tests, and even fewer end-to-end tests at the top.

Not all tests are equal in speed, cost, or what they catch. The testing pyramid is a simple mental model for how to mix them: lots of cheap, fast tests at the bottom and a few expensive, broad ones at the top.

The three layers

The base is unit tests: numerous, fast, and focused on small pieces of code. The middle is integration tests: fewer, slower, checking that components work together. The top is end-to-end tests: the fewest, slowest, and broadest, verifying whole user journeys. The shape, wide bottom, narrow top, is the recommendation.

Why that shape

Fast, cheap unit tests give the quickest, most precise feedback, so you want many of them. End-to-end tests are realistic but slow and flaky, so you want only enough to cover critical paths. Inverting the pyramid, leaning on slow end-to-end tests, makes your suite slow and brittle.

An example

A healthy project might have a few thousand unit tests running in under a minute, a few hundred integration tests running in a few minutes, and a couple dozen end-to-end tests covering signup, checkout, and login. The bulk of coverage comes cheaply from the base.

The anti-pattern: the ice cream cone

The inverse of the pyramid, lots of end-to-end and manual tests with few unit tests, is sometimes called the "ice cream cone." It produces slow, flaky test suites that are painful to run on every change, undermining continuous integration. The pyramid exists to steer teams away from this.

Why it matters for CI

CI runs the whole suite on every change, so its speed and reliability directly affect how often people integrate. A pyramid-shaped suite runs fast and rarely flakes, keeping feedback quick. A top-heavy suite drags out every pull request, which is why the pyramid is a CI-friendly default.

Key takeaways

  • The pyramid favors many unit tests, fewer integration, fewest E2E.
  • Fast cheap tests at the base give the best feedback per second.
  • A top-heavy "ice cream cone" makes CI slow and flaky.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →