Key takeaways
- The test pyramid has three layers: unit tests at the bottom, integration tests in the middle and end-to-end (UI) tests at the top.
- Lower layers are fast, cheap and precise. Higher layers are slow, fragile and broad, but closest to what users do.
- So you want many tests at the bottom and few at the top. The shape is a guide, not a law.
Where the picture comes from
Mike Cohn described the test automation pyramid in his 2009 book Succeeding with Agile. Martin Fowler's later article made it widely known among developers and testers.
The idea is simple: draw your automated tests as a pyramid. The width of each layer shows how many tests of that kind you should have.
The three layers
Bottom: unit tests
They test one small piece of code on its own, such as a function that calculates a discount.
- Speed: milliseconds each. Thousands run in a minute.
- When one fails: it points to the exact piece of code that's wrong.
- Who writes them: usually developers.
Middle: integration tests
They test several pieces together: code with a real database, two services talking, the app calling an API.
- Speed: seconds each.
- When one fails: you know which connection is broken.
Top: end-to-end (UI) tests
They test the whole application the way a user would: open the browser, log in, add to cart, pay.
- Speed: often tens of seconds or more each.
- When one fails: something somewhere in the whole flow is wrong. Finding what takes time.
- Weak spot: they break easily when the page layout changes, and are more likely to be flaky.
| Layer | How many | Speed | Pinpoints the problem? | Closest to the user? |
|---|---|---|---|---|
| End-to-end | Few | Slow | No | Yes |
| Integration | Some | Medium | Partly | Partly |
| Unit | Many | Fast | Yes | No |
Why the shape matters
Imagine all your tests are end-to-end. The suite takes hours, so it runs only at night. A failure says "checkout broke", but not why. Developers find out a day late and spend the morning investigating.
Now imagine most checks happen at the unit level. Developers get feedback in a minute, while the change is still fresh in their minds. The few end-to-end tests then confirm the main flows work together.
That's the point of the pyramid: fast, trustworthy feedback, with each check at the lowest level that can catch it.
In 2015, a post on Google's testing blog called "Just Say No to More End-to-End Tests" argued against relying mainly on end-to-end tests.
End-to-end tests look like the user, the post said, but they're slow, often unreliable and hard to debug when they fail. As a first guess, it suggested a split of about 70% unit, 20% integration and 10% end-to-end tests, adding that the exact mix depends on the team.
Lesson: even at a company with huge testing resources, the advice was to push tests down the pyramid, and keep a small number at the top for what only they can check.
What it means for a beginner tester
- You'll probably start at the top. Manual testers moving into automation often write UI tests first. That's fine, just don't try to test everything there.
- Ask what's covered below. If the discount calculation has 30 unit tests, your UI test only needs to check the discount appears in checkout.
- Think about the right layer. Before automating a check, ask: "What's the lowest layer where this could be tested?"
Check yourself
You want to check that a VAT calculation is correct for 20 different amounts. Which layer of the pyramid should those checks be in?
Show answer
The unit layer. Twenty unit tests run in milliseconds and point straight to the calculation if one fails. At the UI level, the same 20 checks would take minutes and be fragile. One end-to-end test that VAT appears correctly in checkout is enough on top.
