**Episode 18:** by Veenita Joshi and Prakhar Asthana in
Mountain View, CA (February 2021)  

[Previous episodes](https://developer.chrome.com/docs/chromium/chronicle)

**Test coverage measures how much source code is executed** when a particular
test suite runs. Generating coverage data has three major steps: compiling
with instrumentation, gathering data from running instrumented tests, and
post-processing the data. The coverage team has tools to automate this process.

The [Coverage script](https://chromium.googlesource.com/chromium/src/+/master/tools/code_coverage/coverage.py) **can generate code coverage reports in just one command** ,
without waiting for [Gerrit UI to be updated](https://developer.chrome.com/blog/chromium-chronicle-3.md.txt).
This script is currently supported on Linux, Mac, iOS and ChromeOS.

Here is a sample usage:

```bash
$ gn gen out/coverage \
    --args='use_clang_coverage=true is_component_build=false'
$ python tools/code_coverage/coverage.py \
    crypto_unittests url_unittests \
    -b out/coverage -o out/report \
    -c 'out/coverage/crypto_unittests' \
    -c 'out/coverage/url_unittests --gtest_filter=URLParser.PathURL' \
    -f url/ -f crypto/
```

This builds and runs the `crypto_unittests` and `url_unittests targets`. For
`url_unittests`, it only runs the test `URLParser.PathURL`. The coverage
report is filtered to include only files and sub-directories under `url/`
and `crypto/`. Aside from automating the process, **this script provides
additional features to view code coverage by directories and components**.
![Screenshot of output from coverage script.](https://developer.chrome.com/static/blog/chromium-chronicle-18/image/screenshot-output-cover-0b240b2f2339c.png) Directory View ![Screenshot of output from coverage script.](https://developer.chrome.com/static/blog/chromium-chronicle-18/image/screenshot-output-cover-0a9efcf0c1ca4.png) Component View

The [Code Coverage tool](https://analysis.chromium.org/p/chromium/coverage/dir?host=chromium.googlesource.com&project=chromium/src&ref=refs/heads/master&revision=fda1eab599aa18a4731275a74385c13d546bb7f6&path=//this/path/is/set/&platform=linux) provides a code coverage breakdown by directory
and component for the whole codebase, for Windows, iOS, Android, Linux and
ChromeOS.

**Share your feedback:** Contact `code-coverage @ chromium.org` or file a bug
on [crbug.com](https://issues.chromium.org/issues/new?noWizard=true&template=0&component=1456421).

## Resources

- See the [code coverage for the whole codebase](https://analysis.chromium.org/p/chromium/coverage) and a breakdown by directories and components.