Test Pyramid
Mike Cohn's pyramid: many fast unit tests at the base, fewer integration, very few E2E. Avoid the ice-cream-cone anti-pattern.
Overview
The test pyramid
The test pyramid is Mike Cohn's mental model from Succeeding with Agile (2009) for distributing automated tests across levels of granularity. The shape is a triangle: widest at the base, narrowest at the top. Each level holds a different kind of test.
- Unit (the base): many tests, each running in milliseconds and isolated from external dependencies. They test individual classes, functions and modules. They make up about 70% of the suite.
- Integration or service (the middle): fewer tests, each taking seconds. They test boundaries such as database access, HTTP clients and message queues, with the system under test in a controlled environment. They make up about 20%.
- End-to-end or UI (the top): few tests, each taking tens of seconds to minutes. They test the full system as a user would use it. They make up about 10%, the slowest share.
> [!NOTE] The ~70% unit, ~20% integration, ~10% E2E split is frequently quoted. It is a heuristic, not a law.
Key concepts
- Test pyramid (Cohn 2009)
- Unit test
- Integration test
- Contract test (Pact)
- End-to-end (E2E) test
- Ice-cream cone anti-pattern
Interview questions
- Explain the test pyramid and why the proportions matter.
- What is the ice-cream cone anti-pattern and why does it happen?
- Where do contract tests fit, and why are they increasingly popular?
Sign up free to read the full topic
More DevOps topics
- Terraform — Production Errors, Mistakes and Recovery
- Terraform & OpenTofu
- Terraform count vs for_each
- Terraform Essentials — Plan and Apply, Variables, Outputs, Data Sources, and Sharing State at Scale
- Terraform in CI/CD Pipelines
- Terraform Remote State — S3 + DynamoDB
- The C/C++ Compilation Model
- The flux CLI
- The Three Ways
- Toil Reduction & Automation Strategy
- Trunk-Based Development
- Trunk-Based Development with Continuous Deployment
Start free on Cariara · Coding problems · System design studio