#cargo #subcommand #coverage #kcov

app cargo-kcov

Cargo subcommand to run kcov to get coverage report on Linux

12 releases

Uses old Rust 2015

0.5.2 Oct 13, 2018
0.5.1 Jul 14, 2018
0.5.0 May 9, 2018
0.4.2 Sep 23, 2017
0.2.0 Jun 4, 2016

#200 in Cargo plugins

Download history 105/week @ 2022-03-01 70/week @ 2022-03-08 106/week @ 2022-03-15 74/week @ 2022-03-22 47/week @ 2022-03-29 29/week @ 2022-04-05 32/week @ 2022-04-12 51/week @ 2022-04-19 99/week @ 2022-04-26 115/week @ 2022-05-03 249/week @ 2022-05-10 81/week @ 2022-05-17 161/week @ 2022-05-24 138/week @ 2022-05-31 77/week @ 2022-06-07 75/week @ 2022-06-14

455 downloads per month

MIT license

917 lines


Build status Coverage Status crates.io MIT

Collect test coverage on all the test cases for the current project using kcov on Linux and macOS.


In the project run

$ cargo kcov

It will run all test cases and collect coverage statistics via kcov. The coverage report can be read from target/cov/index.html.


You need to install kcov v26 or above to collect coverage report from Rust. Some distro is still shipping v25 or v11, so you will need to build from source.

For macOS, you will need kcov v35 or above. Be aware that macOS performance is significantly slower when compared with Linux. If you are collecting coverage statistics on the CI and you don't have time to spend, consider ignoring macOS.

Please follow the instruction in https://users.rust-lang.org/t/650. cargo-kcov requires v30 or above since earlier versions of kcov do not report its version number.

cargo-kcov requires Rust 1.20.0 or above (due to bitflags dependency).


cargo-kcov can be installed with cargo install.

$ cargo install cargo-kcov


cargo-kcov 0.5.1
Generate coverage report via kcov

    cargo kcov [OPTIONS] [--] [KCOV-ARGS]...

        --lib                      Test only this package's library
        --bin <NAME>...            Test only the specified binary
        --example <NAME>...        Test only the specified example
        --test <NAME>...           Test only the specified integration test target
        --bench <NAME>...          Test only the specified benchmark target
    -j, --jobs <N>                 The number of jobs to run in parallel
        --release                  Build artifacts in release mode, with optimizations
        --features <FEATURES>      Space-separated list of features to also build
        --no-default-features      Do not build the `default` feature
        --target <TRIPLE>          Build for the target triple
        --manifest-path <PATH>     Path to the manifest to build tests for
        --no-fail-fast             Run all tests regardless of failure
        --kcov <PATH>              Path to the kcov executable
    -o, --output <PATH>            Output directory, default to [target/cov]
    -v, --verbose                  Use verbose output
        --all                      In a workspace, test all members
        --open                     Open the coverage report on finish
        --coveralls                Upload merged coverage data to coveralls.io from Travis CI
        --no-clean-rebuild         Do not perform a clean rebuild before collecting coverage. This improves performance
                                   when the test case was already built for coverage, but may cause wrong coverage
                                   statistics if used incorrectly. If you use this option, make sure the `target/`
                                   folder is used exclusively by one rustc/cargo version only, and the test cases are
                                   built with `RUSTFLAGS="-C link-dead-code" cargo test`.
        --print-install-kcov-sh    Prints the sh code that installs kcov to `~/.cargo/bin`. Note that this will *not*
                                   install dependencies required by kcov.
    -h, --help                     Prints help information
    -V, --version                  Prints version information

    <KCOV-ARGS>...    Further arguments passed to kcov. If empty, the default arguments `--verify --exclude-
                      pattern=$CARGO_HOME` will be passed to kcov.


~76K SLoC