Skip to main content

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:

The test pyramid as shown on martinfowler.com: unit tests at the wide bottom, service tests in the middle and UI tests at the narrow top, with tests becoming slower and more integrated towards the top

Screenshot of martinfowler.com, “The Practical Test Pyramid”. Read the full article there.

LevelWhat it checksIn TestRun BoardSpeed
Unit tests (many)One small piece of logic in isolationformatDuration(63000) returns "1m 03s"Milliseconds
API / service tests (some)Parts working together through an interfaceThe /api/runs response has the fields the page needsSeconds
UI / end-to-end tests (few)A real user flow in a real browserOpen the page and see seven test runsSeconds 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:

  1. How likely is it to break? New code, complex logic and frequently changed areas break more often.
  2. 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

  1. 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.tsx and tests/e2e/.)
  2. Count them. Does the suite look like a pyramid?
  3. 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.