Overview
cargo nextest run is a drop-in replacement for cargo test that has become the
professional default. It executes each test in its own process with a smarter scheduler,
which buys isolation (one segfault or env-var mutation can't poison siblings), better
parallelism on mixed-duration suites, per-test timeouts, automatic retries for flaky
tests, and CI-grade features — partitioning across machines, JUnit XML — that the
built-in libtest runner never grew.
Key points
- Process-per-test: the defining design choice. Slower per-test floor, but true isolation — leaked state, aborts and segfaults are contained and reported per test.
- The output is the daily win: a live status line, slowest-tests list, and failures re-printed together at the end — against libtest's interleaved wall of text.
- Retries & flakiness policy:
--retries 2marks pass-on-retry as flaky rather than silently green — surfacing the flake list instead of burying it. - Per-test timeouts (
slow-timeout,terminate-after): hung tests fail with a stack of what was running, instead of hanging the CI job. - CI partitioning:
--partition count:1/4shards a suite across runners with balanced durations;--profile ciin.config/nextest.tomlholds the CI-specific settings (JUnit output path, retries, fail-fast off). - Doctests stay behind: libtest still owns them — CI runs
cargo nextest run && cargo test --doc. The one wart to remember. - Filtersets:
-E 'test(parse) & package(core)'— a small expression language for selecting tests by name/package/kind, beyond substring matching.
Examples
cargo install cargo-nextest --locked
cargo nextest run # the new default
cargo nextest run --retries 2 -E 'package(api)'
cargo nextest run --partition hash:1/4 # CI shard
cargo test --doc # doctests still need libtest
Related
- The Rust toolchain — parent catalog.
- Unit testing — the tests this runner executes.
- rustdoc & docs.rs — the doctests it delegates back to libtest.
- go test — Go's built-in runner, which grew many of these features (caching, sharding culture) first-party.