Topic 4 of 5 · 4 min read
Designing a risk-based test plan
Goal: Write a test plan that maps each risk of a feature to the cheapest test level that catches it, and explain why 90 % line coverage can still miss the bug.
A test plan starts from the risks of a feature, then picks the cheapest test level that would catch each one. Coverage numbers are a side effect, not the goal. It takes ten minutes and tells an agent, and your reviewers, what "tested" means for this change.
Check yourself · 1 of 3
What does 90 % line coverage tell you?
Why it matters
Asked to "add tests", an agent writes whatever is easy: many happy-path unit tests and a high coverage figure. The riskiest part, such as money rounding, permission checks or a retry that charges twice, may have no test. A plan written first aims the effort where a failure would hurt.
How to write one
- List the risks. For a "refund an order" feature: refund more than was paid, refund twice, refund someone else's order, partial refund rounding, the payment provider times out.
- List edge cases before the happy path: empty, zero, maximum, duplicate, wrong user, wrong state, slow dependency.
- Pick the cheapest level that catches each risk. Rounding is a unit test. A double refund needs a real database with a constraint, so an integration test. Permission checks are an integration test through the real API. The full flow through the UI gets one end-to-end test.
- Say what you will not test, and why. Written down, the gap is a decision, not an accident.
- Check the plan with a deliberate bug. After the tests exist, break one risk on purpose and confirm a test fails.
What coverage does and does not prove
Line coverage tells you which lines ran during the tests. It does not tell you that anything was checked. A test that calls a function and asserts nothing gives full coverage and no protection. Coverage also cannot show code that is missing, such as a permission check nobody wrote. High coverage is a reason to look elsewhere, low coverage is a reason to look here. Mutation testing, which changes the code and asks whether a test notices, measures checking more directly.
Before and after
Weak plan: "Add unit tests for RefundService, target 90 % coverage."
Better plan: a table with the risk, the level and the test name: "double refund / integration / refund twice returns 409 and the balance changes once".
What goes wrong
- Chasing a coverage target. Agents will happily generate assertion-free tests to reach it.
- Testing everything at one level. All end-to-end is slow; all unit is blind to wiring.
- Skipping the risks that are hard to test, which are often the ones that matter.
- A plan written after the code. It then describes the code, not the risks.
Examples
Plan for a refund feature
| Risk | Level | Test |
|---|---|---|
| Rounding on a partial refund | Unit | 33.33 split three ways adds up to 99.99 or the rule's stated total |
| Refund twice | Integration | Second call returns 409; balance changes once |
| Refund another user's order | Integration | Returns 403 through the real API |
| Provider timeout | Integration with a fake provider | Order stays pending, no money lost |
| Whole flow | End-to-end | Support agent refunds an order in the admin UI |
Not tested: the email wording, covered by manual review.
Full coverage, missing check
export function cancelOrder(user, order) {
order.status = "cancelled";
return order;
}
A test calls cancelOrder and reaches 100 % line coverage. No line checks that user owns the order, because that code does not exist. Coverage cannot report it; a risk list would have.
Key points
- Start the plan from the risks of the feature, not from the files you changed.
- List edge cases first: empty, zero, duplicate, wrong user, wrong state and slow dependencies.
- Map each risk to the cheapest test level that would catch it.
- Line coverage shows what ran, not what was checked, and it cannot show code that was never written.
- Write down what you will not test so the gap is a decision.
Common mistakes
- Setting a coverage target and letting an agent reach it with assertion-free tests.
- Writing the plan after the code, so it only describes what was built.
- Putting every risk at one test level instead of the cheapest level that catches it.
- Leaving out the hard-to-test risks such as double submits, timeouts and permissions.
Check yourself · 2 of 3
For a refund feature, which risk is best covered by an integration test with a real database?
Check yourself · 3 of 3
You ask an agent to add tests to a new feature. What should you ask for before it writes any test?
Practice items, not counted towards your mastery.
Start here
- The Practical Test Pyramid (martinfowler.com) (opens in a new tab)ArticleFree
Walks through unit, integration and end-to-end levels with code, and why to push tests to the lowest level that catches the bug.
- Software Engineering at Google (free online book) (opens in a new tab)BookFree
The testing chapters cover test size, flakiness and what a useful test suite looks like at scale.
- Playwright documentation (opens in a new tab)DocsFree
How to write and run browser tests with auto-waiting, the basis for stable end-to-end flows.
More for this topic
- Test Coverage (martinfowler.com) (opens in a new tab)ArticleFree
Explains why coverage finds untested code but says little about test quality.