Home

Code Coverage in Rust

When you're writing tests it can be useful to know what in your codebase haven't been tested. Checking the code coverage will show you what individual lines haven't been tested and will let you go in and fill the gaps in your test suite.

With Rust you can do this using the LLVM code coverage tools.

There's a lot of info here in the rustc book. For the abridged version install the cargo llvm-cov helper.

cargo install cargo-llvm-cov

Once that installs, run your tests like so:

cargo llvm-cov --open

This will open your browser to an LLVM HTML coverage report showing the tree of files in your codebase. Click through to the files that you're currently testing, and you'll see the lines that are covered and the lines that are not:

coverage report showing lines covered and not covered in the tokio codebase