Course map

Topic 197 / Core

Testing strategy and test levels: unit, component, integration, end-to-end, regression, migration, recovery

Chapter 12.3 · Testing Strategies

What and why

No single kind of test catches every kind of bug cheaply — a test that exercises the whole system catches real integration problems but runs slowly and flakily; a test that exercises one function runs instantly but can't see what breaks between components. A test strategy is the deliberate mix of test levels, each catching a different class of problem at the cost that level is willing to pay, so the test suite as a whole is fast and trustworthy rather than exhaustive and flaky. Builds on: → 195 (disaster recovery, RTO and RPO: recovery drills — recovery, one of this topic's levels, is already a drilled, scheduled test).

Diagram

Level Scope Speed Catches
Unit one function/class, dependencies faked fast (ms) logic bugs, edge cases
Component one service, real dependencies containerized moderate this service's real behavior
Integration two or more real services/components talking slower boundary mismatches
End-to-end a full, critical user journey slow, few of these the journey actually works
Regression re-runs of whatever broke before varies old bugs coming back
Migration a schema or data move (→ 189) run before production data-shape surprises
Recovery a restore (→ 80) or failover (→ 194, → 195) scheduled, infrequent the plan everyone assumed worked

How it works

  1. Write many fast, isolated unit tests — the cheapest place to catch a logic bug, and the layer that should fail loudest and first.
  2. Write component tests against real, containerized dependencies (e.g., a real Postgres or Redis in a test container) for behavior unit tests can't see — a real query, a real cache miss.
  3. Write integration tests across real service boundaries where two systems' assumptions about each other matter most, and reserve end-to-end tests for the small number of journeys whose failure is unacceptable — few, because they're slow and more prone to flaking.
  4. Keep every bug that ever escaped to production as a regression test, so the suite remembers failures the team has already paid to find once.
  5. Test migrations (→ 189) and recovery procedures (→ 80, → 195) as first-class, scheduled tests, not one-off manual steps — a migration tested only by eyeballing staging, or a recovery plan never actually executed, is untested in the sense that matters.

Practical example

(illustrative). A service's suite: 1,000 unit tests at 10 ms each = 10 s; 50 component tests at 2 s each = 100 s; 10 integration tests at 5 s each = 50 s; 3 end-to-end tests at 30 s each = 90 s. Total CI runtime ≈ 10 + 100 + 50 + 90 = 250 seconds, and a failure in a unit test is isolated to one function within the first 10 seconds of the run — compare this to an "ice-cream-cone" suite of 3 unit tests and 1,000 end-to-end tests, whose first useful failure signal might not arrive for most of a 1,000 × 30 s = 8.3-hour run.

When to use it

  • Use a pyramid shape: many fast unit tests, fewer component/integration tests, a handful of end-to-end tests — matching the diagram's speed-vs-scope trade-off.
  • Avoid the inverted "ice-cream cone": mostly slow, broad tests and few fast, narrow ones — slow to run, slow to diagnose, and the first thing a deadline cuts.
  • Failure scenarios: flaky end-to-end tests that get re-run until green, eroding trust in the whole suite until failures are ignored by habit; a migration tested only in staging against synthetic data that doesn't resemble production's real data shape; a recovery procedure that exists only as a document, never actually executed end to end.
  • Simpler alternative: for a small, low-risk service, unit tests plus one or two end-to-end smoke tests may be the entire pyramid needed — add component and integration levels only once real boundary bugs start appearing.

Practice

(process kind — fill the template on a small real system; 20 min). For Project 1's task app (or a system you know), list its current tests by level, mark which levels are missing, and write one example test name for each missing level (unit, component, integration, end-to-end, regression, migration, recovery) describing exactly what it would check. Done when every level in the diagram has at least one named, concrete test idea attached to it.

Key takeaway

A test strategy is a deliberate mix of levels, each catching a different class of problem at a cost it's worth paying — fast and many at the bottom, slow and few at the top. Done when you can: classify any test by level and justify why it belongs there rather than one level up or down. Used next in → 198 (contract testing, deepening the integration level), → 199 (performance test types, a category this taxonomy doesn't cover), → 200 (chaos testing, failure-level testing).

References

None — this topic makes no external claims.

Source directory

Search the guide