Cover Code with Tests

Many companies have standards for the percentage of code with unit test coverage they should have. To me, the only number that makes sense is 100%.

Knowing that we’re not always going to be able to achieve that, as developers, we still want to strive for it, even when we have dependencies on other services that may make parts of our code untestable.

Code coverage tools show you where your code is covered by unit tests. The discussion of what is the best percentage of code coverage to shoot for can set us up to game the system. I’ve seen companies have test coverage targets of 60%, 80%, or whatever, and developers use it as an excuse for not writing tests. They leave the hard-to-test code untested and cover trivial code ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.