Your test suite
Cargo
variance cargo runs your tests with
rustc's coverage counters, with no llvm-cov installed, and writes it. Then
variance select names the test targets a change did not reach, and
variance covering names the tests that ran a function.Try it
The CLI is a Node package, so you need Node 22.15 or newer. Install it at the
repository root, beside your Cargo.toml, and declare the suite in
variance.config.json there:
npm install --save-dev @variance-authority/cli
{ "suites": { "unit": { "kind": "unit" } } }
Record once, from the crate or the workspace root. What follows -- goes to
cargo test, and a test filter there is refused, since every test the build
lists runs:
variance cargo --suite unit -- --workspace --lib --locked
It exits 0 when every test passed and 101 when a test or the build failed.
Doctests are not run, so run cargo test --doc beside it.
What you get
Leave out the test targets a change did not reach
Cargo does not leave targets out itself. After you change a function, ask:
variance select --suite unit --since origin/main
It prints the test files the change does not reach, one per line, and each is
one target: src/lib.rs is the crate's --lib, and tests/negates.rs is
--test negates. Run cargo test with the targets that were not printed. A
change to Cargo.toml, Cargo.lock or a build script selects every target.
Ask which tests ran a function
variance covering --file src/lib.rs --function add
unit (unit):
2 named tests covered function add of src/lib.rs:
src/lib.rs — 2/3
tests::adds
tests::muls
A method is named by the impl around it, such as Calc/twice. What a row
holds says how each function is named.
Not yet
- The runner leaving targets out itself:
variance selectprints them, for the script that runscargo testto leave out. - Skipping tests inside a selected target: every test in it runs.
- Shard placement by recorded time.
- Test stories and visual review.
Go further
- The Cargo reference: what
variance cargobuilds and runs, and what it costs. - How it differs from
cargo test, each test in its own process. - When a left-out Cargo test could still have failed, from build scripts to
include_str!. - Supported frameworks puts Cargo beside every other runner.