Short answer
The test pyramid is a rule: many fast unit tests at the bottom, fewer integration and API tests in the middle, and the fewest E2E tests through the UI at the top. A commonly quoted ratio is 70/20/10, for example 500 unit tests, 150 API tests and 20-30 E2E tests in a mid-sized web app. More important than the percentages is one rule: check everything at the lowest level where it can be checked. Then the whole regression takes minutes, not hours.
Three levels
| level | what it checks | time per test | usually written by |
|---|---|---|---|
| unit tests | a function or class in isolation, e.g. calculating VAT | milliseconds | developers |
| integration and API tests | working with a database, a queue, another service; API endpoints | tens of milliseconds to seconds | developers and testers |
| E2E tests | a whole user path through the UI, e.g. sign-up and payment | a few seconds to a minute | testers |
Example: a booking app
| level | number of tests | what we test | time for the whole suite |
|---|---|---|---|
| unit | about 500 | prices, discounts, slot availability, validation | about 1 minute |
| API | about 150 | booking, cancellation, payment, permissions, negative scenarios | 3-5 minutes |
| E2E | 20-30 | sign-up, login, booking with payment, cancellation, admin panel | 10-15 minutes |
The same discount rules checked in 40 E2E tests would take over ten minutes and break with every visual change. As unit tests they take a fraction of a second. The E2E test only checks that the discount reaches the cart at all.
How to shape the pyramid in your project
- List 5-10 critical paths and turn them into E2E tests. That’s the top.
- Move business rules down. Every data variant and edge case that can be checked without a browser goes into unit or API tests.
- Add negative API tests: missing fields, no token, someone else’s resource, a duplicate. I list them in 15 negative REST API test scenarios.
- Set the times: a smoke test on a pull request in a few minutes, full regression in ten to a few dozen minutes. How to split this in CI is covered in regression in CI.
- Leave room for exploratory testing. The pyramid is about automated tests. New features are still worth going through by hand before they go into automation.
When the shape is different
- A frontend app with little server logic. More component integration tests, fewer unit tests. This shape is sometimes called the testing trophy.
- Many services talking over APIs. Add contract tests, which make sure a change in one service doesn’t break the others.
- A mobile app. E2E tests on devices are slower and more expensive, so the top should be even narrower, with more logic checked through the API.
The inverted pyramid and how to get out of it
An inverted pyramid means many E2E and manual tests and few unit and API tests. Symptoms: regression takes hours, tests are often flaky, and when a test fails nobody knows what broke. The way out isn’t throwing away E2E tests but gradually moving checks down: for every flaky or slow E2E test, ask whether the same thing can be checked with an API test.
How I can help
As part of test automation I build E2E tests of the critical paths in Playwright, and as part of API testing an API test suite with negative scenarios. If you already have many tests and regression takes too long, I’ll start by reviewing which tests to move down. Describe your project in the contact form.