Readplace

The Myth Of 100% Code Coverage

fagnerbrack.com 6 min read
View original
Summary (TL;DR)
Chasing 100% code coverage via lines of code leads to useless tests and brittle code. Tests for DTOs or React internals inflate coverage but don't verify business behavior, coupling tests to implementation details. Goodhart's Law warns that when coverage becomes a target, people game it. Instead, focus on covering business use cases by testing the external API of models. Design code to minimize coupling (e.g., inject dependencies, avoid mocking imports). Mutation testing helps but can't catch everything. Only skilled humans, not tools, can judge if tests cover the right behavior. Proper 100% coverage means all business scenarios are tested, not all lines.