Two Testing Pitfalls in Layered Systems: Over-Mocking and Snapshot Sprawl
Tests that punish refactoring teach teams to stop refactoring. Two traps layered code invites: mocking inside a layer and snapshotting a volatile one.
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.
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:
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.
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.
The book credits three properties of the dependency rules for making this arrangement work.
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 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.