The LVD Testing Pyramid

Most teams have heard that tests should look like a pyramid: many small ones at the bottom, a few big ones at the top. Fewer can say what "small" means in their own codebase, or which part of the system deserves the most scrutiny. LVD answers both questions by tying each rung of the pyramid to a layer.

One layer, one kind of test

The classic pyramid is a statement about proportions. LVD makes it a statement about addresses. Starting from the base, the book assigns each layer the style of test that suits its nature:

  • Schema (L1): validation tests that exercise every rule.
  • Utils (L2): plain unit tests of pure functions, including property-based ones.
  • Resources (L3): integration tests against real or containerised databases, HTTP services and queues.
  • Tools (L4): business-logic tests with mocked resources and injected dependencies.
  • API (L5) and MCP (L6): contract tests that check requests and responses.
  • UI (L9): component tests that check rendering, interaction and accessibility. This rung is new in the second edition and sits between contract tests and the apex.
  • Agents (L8): end-to-end tests of whole workflows and user journeys.

Width stands for how many tests you have, and height for how much each one costs and how easily it breaks. The base is a crowd of quick, repeatable schema checks. The apex is a handful of slow tests that can be upset by the state of the environment.

Targets that follow blast radius

Because the layers differ in cost and in the damage a defect can do, the book refuses to set one number for everything. Instead it prescribes a different coverage target for each layer: 100 per cent for Schema, 95 or more for Utils, 90 or more for Tools, 85 or more for API, 80 or more for Resources, and for end-to-end tests a focus on critical paths rather than a percentage. The UI target is offered as a proposal, 80 or more overall and 90 or more for shared components.

The reasoning is a cost-benefit one. Schemas are the contract between every layer, so a validation gap spreads errors everywhere, yet they are cheap to test because they are fast and involve no I/O. Resources talk to external systems, so reaching 100 per cent is impractical, and the book steers effort towards retry logic, error handling and data mapping. Full end-to-end coverage costs too much, so the aim is the fraction of workflows that carry most of the value.

Notice what this implies for a team that has 90 per cent coverage on its database adapters but only half of that on its business logic. The effort is in the wrong place: the layer where a bug does the most harm is the one being tested least.

Why the structure helps

The book credits three properties of the dependency rules for making this arrangement work.

  1. Isolation by construction. Lower layers cannot depend on higher ones, so a Schema or Utils test never needs to mock a tool or an endpoint. The dependency graph is acyclic, so layers can be tested in topological order with no circular mocking.
  2. Substitutability. Resources is an adapter over external systems, which means every outside dependency already has a defined interface. Tools depend on that interface, so injecting a fake is the natural thing to do.
  3. A determinism gradient. The lower you go, the more deterministic the code: pure functions and static schemas. The higher you go, the more effectful it becomes, with network calls and user actions. Test suites inherit that gradient, so the base is rock solid and the flakiness concentrates at the apex, where retries and environment controls can contain it.

The UI adds a fourth, smaller benefit. Since the UI reaches the server only through the generated client in its services folder, a UI test mocks the network in exactly one place.

The takeaway

The LVD pyramid is less about the shape than about the labels. Each layer names the test it needs and the cost it is worth paying, and the dependency rules keep those tests independent of one another. The numbers feed straight into lvd-metrics, which can enforce them per layer. Next, see how each layer is tested in practice: the lower layers and the upper layers.

What the book covers

  • The full pyramid diagram with the test style for each layer
  • The coverage target and rationale for every layer
  • The proposed targets for the UI layer, including shared components
  • Three structural properties that make layered code easier to test