Coverage & CI
Coverage measures which lines executed during tests. cargo-llvm-cov integrates with Rust's LLVM coverage and fits CI pipelines alongside fmt, clippy, and nextest.
Search across all documentation pages
Coverage measures which lines executed during tests. cargo-llvm-cov integrates with Rust's LLVM coverage and fits CI pipelines alongside fmt, clippy, and nextest.
cargo install cargo-llvm-cov
cargo llvm-cov --workspace --lcov --output-path lcov.info# CI excerpt
- run: cargo llvm-cov --workspace --fail-under-lines 70When to reach for this: Tracking test gaps on critical crates and preventing coverage regressions on main.
name: ci
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.97.0
- run: cargo fmt --check
- run: cargo clippy --workspace --all-targets -- -D warnings
- run: cargo nextest run --workspace
- run: cargo install cargo-llvm-cov
- run: cargo llvm-cov --workspace --lcov --output-path lcov.info
- uses: codecov/codecov-action@v4
with:
files: lcov.infoWhat this demonstrates:
--fail-under-lines gate on PRs| Metric | Notes |
|---|---|
| Line coverage | Common CI metric |
| Branch coverage | Harder; llvm-cov focus on regions |
Uncovered match arms | High-value targets |
Coverage does not equal correctness. Pair with clippy, property tests, and review.
cargo llvm-cov --open # HTML report
cargo llvm-cov --summary-only # quick terminal summaryExclude generated code and #[cfg(test)] only modules via config file .llvm-cov.toml if needed.
cargo test or nextest passes first in CI job.cargo llvm-cov --doc separately if policy includes docs. Fix: document which targets count toward gate.| Alternative | Use When | Don't Use When |
|---|---|---|
tarpaulin | Linux-only quick setup | Cross-platform llvm consistency needed |
| No coverage gate | Early prototype | Production payment/auth paths |
| Mutation testing | Test quality audit | Default CI (expensive) |
llvm-cov uses rustc's native instrumentation; generally preferred for accuracy and workspace support.
Start 60-70% lines on domain crates; ratchet upward; never block on generated/boilerplate modules.
Yes by default when running full workspace test; use -p to scope.
.llvm-cov.toml ignore patterns for build.rs output and tests/fixtures.
llvm-cov works; ensure Xcode/clang toolchain available on runner.
Upload per-job lcov; Codecov merges reports from OS/feature matrix.
No unless you run benches under llvm-cov explicitly; benches are separate targets.
Run --all-features job separately; coverage can differ per cfg.
Codecov or similar posts diff coverage on changed lines.
Run from root with --workspace; same as tests.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 19, 2026