Improve Your Testing #10: Learn From Code Coverage.

Many use code coverage as a quality metric to meet, but it has a much better use.

David Rodenas PhD
12 min read1 day ago
«That’s not what coverage is», prompted by the author.

Code coverage is one of the least understood metrics in the software world. Yes, everyone knows it’s the proportion of code covered by tests, but many are under the impression that it has a direct correlation with code quality. Well, that’s not the case. More test coverage doesn’t imply better quality. It can even be the opposite, where increasing coverage ends up with worse quality. However, it has a much better objective: to understand and learn more about our code and how it relates to the test.

Where does code coverage not work?

Unfortunately, code coverage is often used as a metric to “ensure” a minimum quality. This belief is so strong that there are even American agencies that require a minimum code coverage. And here I have the case of a former colleague, who wanted to sell the software to the Food and Drug Administration (FDA), but the FDA demanded minimum coverage. They had no tests. So they spent three months frantically adding tests. One of the worst professional experiences he ever had. At first, the tests made sense, but eventually, they were just covering code and nothing more. There was no need to change a single line of code because…

--

--

David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.