# Testing/testing Strategy Pyramid

> How to balance a test portfolio across unit, integration, and end-to-end layers using the test pyramid (and the testing-trophy alternative).

- Skill: `gabriel7silva/testing-testing-strategy-pyramid` (Agent Skill)
- Install (CLI): `npx get-skill add gabriel7silva/testing-testing-strategy-pyramid`
- Raw SKILL.md: https://api.skillmd.com/api/skills/gabriel7silva/testing-testing-strategy-pyramid/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: gabriel7silva (https://skillmd.com/u/gabriel7silva)
- Updated: 2026-11-24
- Page: https://skillmd.com/skills/gabriel7silva/testing-testing-strategy-pyramid

---


# 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
- Bliki — Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html
- Article — The Practical Test Pyramid (Ham Vocke): https://martinfowler.com/articles/practical-test-pyramid.html

## 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
```text
        /\        few   UI / end-to-end tests   (slow, broad, brittle)
       /  \
      /----\      some  service / integration tests
     /      \
    /--------\    many  unit tests              (fast, isolated, cheap)
```

## Further reading
- The Practical Test Pyramid: https://martinfowler.com/articles/practical-test-pyramid.html
- Testing Trophy (community, Kent C. Dodds): https://kentcdodds.com/blog/the-testing-trophy-and-testing-classifications

## Related skills
- ../unit-integration-e2e — the tooling that implements each layer
- ../tdd-and-coverage — writing the low-level tests first and measuring meaningful coverage

