Getting Started

The gcovr command provides a summary of the lines that have been executed in a program. Code coverage statistics help you discover untested parts of a program, which is particularly important when assessing code quality. Well-tested code is a characteristic of high quality code, and software developers often assess code coverage statistics when deciding if software is ready for a release.

GCC can instrument the executables to emit coverage data. You need to recompile your code with the following flags:

--coverage -g -O0

Next, run your test suite. This will generate raw coverage files.

Finally, invoke gcovr. This will print a tabular report on the console.

gcovr

You can also generate detailed or nested HTML reports:

gcovr --html-details coverage.html
gcovr --html-nested coverage.html

Gcovr will create one HTML report per source file and for --html-nested also per directory next to the coverage.html summary.

You should run gcovr from the build directory. The -r option should point to the root of your project. This only matters if you have a separate build directory. For example:

cd build; gcovr -r ..