Recipe
Test Pyramid Design
Structure your test suite for speed, confidence, and maintainability using the classic three-tier pyramid model.
Overview
The test pyramid is a mental model that guides how many tests you write at each level of abstraction. The bottom layer is broad and fast; the top is narrow and slow. The goal is to catch bugs as early and cheaply as possible.
The Three Tiers
U
Unit Tests
Many. Test individual functions and methods in isolation. Fast, deterministic, run on every commit.
I
Integration Tests
Fewer. Verify that modules work together correctly. Hit real databases, APIs, or filesystems.
E
E2E Tests
Fewest. Simulate real user flows through the full stack. Slowest but highest confidence.
Ratio Guidance
70% Unit
20% Integration
10% E2E
These are starting points, not dogma. Adjust based on your risk profile and domain complexity.
Anti-Patterns
- Ice-cream cone: many E2E tests, few unit tests. Flaky, slow CI.
- Mock overuse: unit tests that mock everything test nothing real.
- No integration layer:skipping the middle tier leaves a gap between unit and E2E.