Definition
Testing Pyramid
A metaphor for the optimal distribution of test types in a software project. It suggests that you should have many more low-level unit tests than high-level system tests.
Structure
- Base (Unit Tests): The foundation.
- Volume: Largest.
- Cost: Cheap to write and run.
- Speed: Fast.
- Middle (Integration Tests): The glue.
- Volume: Moderate.
- Cost: More expensive.
- Top (System/E2E Tests): The verification.
- Volume: Smallest.
- Cost: Expensive (slow, flaky, hard to maintain).
- Speed: Slow.
Rationale
- Feedback Speed: Unit tests give instant feedback. Waiting for a 2-hour E2E suite kills productivity.
- Debuggability: When a unit test fails, the bug is right there. When a system test fails, it could be anywhere (network, database, UI, logic).
- Stability: High-level tests are often “flaky” (fail randomly due to timing/environment).
