Code Coverage

In computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high test coverage, measured as a percentage, has had more of its source code executed during testing, which suggests it has a lower chance of containing undetected software bugs compared to a program with low test coverage. (Wikipedia)

This chapter describes how to generate a traditional code coverage report over the Kotlin, Rust, Swift and Python code in the Glean SDK repository. To learn how to generate a coverage report about what metrics your project is testing, see the user documentation on generating testing coverage reports.

Generating Kotlin reports locally

Locally you can generate a coverage report with the following command:

./gradlew -Pcoverage :glean:build

After that you'll find an HTML report at the following location:


Generating Rust reports locally

Generating the Rust coverage report requires a significant amount of RAM during the build.

We use grcov to collect and aggregate code coverage information. Releases can be found on the grcov Release page.

The build process requires a Rust Nightly version. Install it using rustup:

rustup toolchain add nightly

To generate an HTML report, genhtml from the lcov package is required. Install it through your system's package manager.

After installation you can build the Rust code and generate a report:

make rust-coverage

After that you'll find an HTML report at the following location:


Generating Swift reports locally

Xcode automatically generates code coverage when running tests. You can find the report in the Report Navigator (View -> Navigators -> Show Report Navigator -> Coverage).

Generating Python reports locally

Python code coverage is determined using the library.


make python-coverage

to generate code coverage reports in the Glean virtual environment.

After running, the report will be in htmlcov.