Using the Code Coverage Metric Effectively

Code coverage—the percentage of lines of code exercised by your unit tests—is the new “lines of code” metric, sure to be abused by lazy managers. The naive interpretation of the metric is that 100 percent means you have comprehensive coverage, and 0 percent indicates that you haven’t even tried. You can find a number of code coverage tools for C++; most are not free. COVTOOL (http://covtool.sourceforge.net) is one open source test coverage tool.

A good coverage tool will also annotate your source, showing you specifically which lines of code get executed when you run your tests. The real value in measuring coverage lies here: knowing which lines of code aren’t covered can help you determine where you ...

Get Modern C++ Programming with Test-Driven Development 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.