What to Automate: the Test Pyramid and Risk
Why This Matters
You cannot automate everything, and you should not try. AI makes it tempting: ask for tests and you get hundreds. But every test costs time to run and to maintain. The question is not “can we test this?” but “which tests give the most confidence for the least effort?”
The test pyramid
The best-known model for this is the test pyramid, described clearly by Ham Vocke in The Practical Test Pyramid on martinfowler.com:
Screenshot of martinfowler.com, “The Practical Test Pyramid”. Read the full article there.
| Level | What it checks | In TestRun Board | Speed |
|---|---|---|---|
| Unit tests (many) | One small piece of logic in isolation | formatDuration(63000) returns "1m 03s" | Milliseconds |
| API / service tests (some) | Parts working together through an interface | The /api/runs response has the fields the page needs | Seconds |
| UI / end-to-end tests (few) | A real user flow in a real browser | Open the page and see seven test runs | Seconds to minutes |
The shape is the message: many fast, focused tests at the bottom; a few slow, broad tests at the top. A suite that is mostly UI tests is slow, breaks on every design change, and tells you little about where the bug is.
Add risk to the picture
The pyramid tells you where to test. Risk tells you what. For each feature, ask:
- How likely is it to break? New code, complex logic and frequently changed areas break more often.
- How bad is it when it breaks? Payments, data loss and legal texts are worse than a misaligned icon.
Test the high-likelihood, high-impact areas thoroughly and at the lowest level that can catch the problem. A calculation error is best caught by a unit test; a broken checkout flow needs one end-to-end test.
What not to automate
- Things that change every week and are cheap to check by eye.
- One-time checks, such as a data migration you run once.
- Judgements that need a human: “is this easy to understand?”, “does this feel right?”.
Exercise
- Open the TestRun Board repository and look at the
tests/folder. Which files are unit tests, which are component tests and which are end-to-end tests? (Hint:tests/lib/,tests/*.test.tsxandtests/e2e/.) - Count them. Does the suite look like a pyramid?
- For the application you chose in lesson 1, Why Test Automation, and Why It Changes with AI, write one example test for each level of the pyramid, in plain language.
Key Takeaways
- The test pyramid: many unit tests, some API tests, few UI tests.
- Use risk (likelihood × impact) to decide what to test thoroughly.
- Catch each problem at the lowest level that can see it.
- Not everything should be automated; some checks need a human.
