Generating code coverage reports
Being aware of how much of your code is covered by tests is a great benefit and often gives a very good impression of how well-tested a given software is. It can also give hints to developers about the execution paths and edge cases that are not covered by tests.
To get code coverage in C++
There are a few tools that help you get code coverage in C++. Arguably, the most popular is Gcov from GNU. It’s been around for years and works well with GCC and Clang. Although it does not work with Microsoft’s Visual Studio, using Clang to build and run software provides a viable alternative for Windows. Alternatively, the OpenCppCoverage
tool can be used to get coverage data on Windows to build with MSVC.
The coverage information generated by Gcov can be collected in summarized reports with the Gcovr or LCOV tools.
Generating coverage reports using Clang or GCC
In this section, we will look at how to create code coverage reports with...