Testing Strategy: The Test Pyramid
Overview
The test pyramid is a heuristic for shaping an automated test portfolio so that most checks are cheap, fast, low-level tests and only a few are slow, broad, end-to-end tests. Read this when deciding how many tests to write at each layer, or when an existing suite is slow and brittle (a sign of an inverted "ice-cream cone"). It frames the cost/speed/confidence tradeoffs that the sibling tooling and TDD skills then implement.
Official sources
Core concepts
- Three layers. A broad base of many fast unit tests, a middle band of service / integration tests that exercise components through APIs (subcutaneously, bypassing the UI), and a thin top of UI / end-to-end tests.
- Cost and speed rise with the layer. Per Fowler, tests that run end-to-end through the UI are "brittle, expensive to write, and time consuming to run," so higher layers should hold fewer tests.
- Granularity drives the count. The higher a test sits, the more integration it covers per test, so fewer are needed to cover the same ground; lower-level tests isolate behavior and pinpoint failures.
- The pyramid is a heuristic, not a law. Exact layer names and counts matter less than the principle: push tests down to the cheapest level that still gives the confidence you need.
- The ice-cream cone anti-shape. A suite dominated by UI automation with few unit tests inverts the pyramid and becomes slow and fragile.
- Testing trophy (community alternative). A widely discussed alternative weights integration tests more heavily than a strict pyramid; treat it as a perspective, not an official Fowler model (see Further reading).
Best practices
- Write the bulk of automated tests at the unit level and use end-to-end tests as a "second line of test defense" (Fowler).
- When a higher-level test catches a bug, reproduce it with a lower-level unit test before fixing, so the regression is guarded cheaply and locally.
- Keep end-to-end tests focused on a few critical user journeys rather than re-checking logic already covered by unit tests.
- Push assertions to the lowest layer that can make them; reserve UI tests for things only the UI can verify.
Common pitfalls
- Inverting the pyramid (ice-cream cone): over-investing in UI/e2e tests → rebalance toward fast unit and service tests.
- Treating layer labels as rigid rules → focus on the cost/speed/confidence tradeoff the shape represents, not the vocabulary.
- Duplicating the same business logic across every layer → cover logic once at the cheapest layer, integrate (not re-test) above it.
Examples
/\ few UI / end-to-end tests (slow, broad, brittle)
/ \
/----\ some service / integration tests
/ \
/--------\ many unit tests (fast, isolated, cheap)
Further reading
Related skills
- ../unit-integration-e2e — the tooling that implements each layer
- ../tdd-and-coverage — writing the low-level tests first and measuring meaningful coverage
1---2name: testing-testing-strategy-pyramid3description: How to balance a test portfolio across unit, integration, and end-to-end layers using the test pyramid (and the testing-trophy alternative).4domain: engineering5category: engineering6tags: [testing, test-pyramid, strategy, e2e, unit-tests, integration]7official_sources:8 - https://martinfowler.com/bliki/TestPyramid.html9 - https://martinfowler.com/articles/practical-test-pyramid.html10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/testing-testing-strategy-pyramid13---1415# Testing Strategy: The Test Pyramid1617## Overview18The test pyramid is a heuristic for shaping an automated test portfolio so that most checks are cheap, fast, low-level tests and only a few are slow, broad, end-to-end tests. Read this when deciding how many tests to write at each layer, or when an existing suite is slow and brittle (a sign of an inverted "ice-cream cone"). It frames the cost/speed/confidence tradeoffs that the sibling tooling and TDD skills then implement.1920## Official sources21- Bliki — Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html22- Article — The Practical Test Pyramid (Ham Vocke): https://martinfowler.com/articles/practical-test-pyramid.html2324## Core concepts25- **Three layers.** A broad base of many fast **unit tests**, a middle band of **service / integration tests** that exercise components through APIs (subcutaneously, bypassing the UI), and a thin top of **UI / end-to-end tests**.26- **Cost and speed rise with the layer.** Per Fowler, tests that run end-to-end through the UI are "brittle, expensive to write, and time consuming to run," so higher layers should hold fewer tests.27- **Granularity drives the count.** The higher a test sits, the more integration it covers per test, so fewer are needed to cover the same ground; lower-level tests isolate behavior and pinpoint failures.28- **The pyramid is a heuristic, not a law.** Exact layer names and counts matter less than the principle: push tests down to the cheapest level that still gives the confidence you need.29- **The ice-cream cone anti-shape.** A suite dominated by UI automation with few unit tests inverts the pyramid and becomes slow and fragile.30- **Testing trophy (community alternative).** A widely discussed alternative weights integration tests more heavily than a strict pyramid; treat it as a perspective, not an official Fowler model (see Further reading).3132## Best practices33- Write the bulk of automated tests at the unit level and use end-to-end tests as a "second line of test defense" (Fowler).34- When a higher-level test catches a bug, reproduce it with a lower-level unit test before fixing, so the regression is guarded cheaply and locally.35- Keep end-to-end tests focused on a few critical user journeys rather than re-checking logic already covered by unit tests.36- Push assertions to the lowest layer that can make them; reserve UI tests for things only the UI can verify.3738## Common pitfalls39- Inverting the pyramid (ice-cream cone): over-investing in UI/e2e tests → rebalance toward fast unit and service tests.40- Treating layer labels as rigid rules → focus on the cost/speed/confidence tradeoff the shape represents, not the vocabulary.41- Duplicating the same business logic across every layer → cover logic once at the cheapest layer, integrate (not re-test) above it.4243## Examples44```text45 /\ few UI / end-to-end tests (slow, broad, brittle)46 / \47 /----\ some service / integration tests48 / \49 /--------\ many unit tests (fast, isolated, cheap)50```5152## Further reading53- The Practical Test Pyramid: https://martinfowler.com/articles/practical-test-pyramid.html54- Testing Trophy (community, Kent C. Dodds): https://kentcdodds.com/blog/the-testing-trophy-and-testing-classifications5556## Related skills57- ../unit-integration-e2e — the tooling that implements each layer58- ../tdd-and-coverage — writing the low-level tests first and measuring meaningful coverage