Skip to content

Test Pyramid

In one line

The test pyramid says: lots of unit tests (fast, cheap), some integration tests (medium), few E2E tests (slow, expensive).

In simple words

The test pyramid is a guide for how to distribute your tests. Picture a pyramid with three layers:

  • Base (widest): Unit tests — many of them. They're fast (milliseconds), cheap to write and maintain, and give precise feedback. This should be the bulk of your tests.
  • Middle: Integration tests — a moderate number. They're slower and test multiple components together. Use them to verify module boundaries.
  • Top (narrowest): E2E tests — very few. They're slow (seconds), expensive, and brittle. Use them only for critical user flows.

The pyramid shape reminds you: more tests at the bottom, fewer at the top. If your pyramid is inverted (lots of E2E, few unit tests), you'll have slow, brittle test suites that are hard to maintain.

Example

javascript
// Test Pyramid — relative test counts
//
//        ///       /E2E        ← few, slow, brittle
//      /------//     /  Integ      ← moderate
//    /----------//   /    Unit       ← many, fast, isolated
//  /----------------
// Typical distribution in a healthy project:
const testSuite = {
  unit: 500,        // 80% — fast, isolated
  integration: 100, // 15% — real module interactions
  e2e: 25,          // 5%  — critical user journeys only
};

const total = Object.values(testSuite).reduce((a, b) => a + b, 0);
console.log('Unit:', (testSuite.unit / total * 100).toFixed(0) + '%');   // 80%
console.log('E2E:', (testSuite.e2e / total * 100).toFixed(0) + '%');     // 4%

The test pyramid guides test distribution: many fast unit tests at the base, fewer integration tests in the middle, and very few slow E2E tests at the top. This keeps the suite fast and reliable.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary