Gcovr

8.6 · active · verified Fri Apr 10

Gcovr is a Python utility that processes code coverage data generated by the GNU gcov tool for C/C++ projects. It simplifies the creation of summarized code coverage reports in various formats, including text, HTML, XML (Cobertura, SonarQube, JaCoCo), JSON, CSV, and Markdown. Gcovr is currently at version 8.6 and maintains a regular release cadence with several updates throughout the year.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the typical workflow for using gcovr: compiling your C/C++ code with GCC's coverage flags, executing your program to generate coverage data, and then running the `gcovr` command-line tool to produce a human-readable report (e.g., HTML).

# 1. Create a sample C++ file (example.cpp)
#include <iostream>

int foo(int param) {
    if (param) {
        return 1;
    } else {
        return 0;
    }
}

int main() {
    foo(0);
    std::cout << "Hello from main!" << std::endl;
    return 0;
}

# 2. Compile the code with coverage flags
g++ -fprofile-arcs -ftest-coverage -O0 example.cpp -o program

# 3. Run the compiled program to generate .gcda data files
./program

# 4. Generate a coverage report using gcovr (e.g., HTML report)
gcovr -r . --html --html-details -o coverage.html

# To view the report:
# open coverage.html

view raw JSON →