Skip to content
Latchkey

cargo nextest run --profile ci: Faster Test Runs

cargo nextest run executes Rust tests in a separate process per test with parallelism, retries, and JUnit reporting; --profile ci selects CI-tuned settings from nextest.toml.

nextest is a drop-in alternative to cargo test that is faster and gives you flaky-test retries and partitioned sharding, both valuable in CI.

What it does

cargo nextest run builds the test binaries and runs each test in its own process, which improves isolation and speed. Profiles defined in .config/nextest.toml (such as ci) control retries, timeouts, and reporters like JUnit XML.

Common usage

Terminal
cargo nextest run --workspace --profile ci
cargo nextest run --retries 2 --no-fail-fast
cargo nextest run --partition count:1/4       # shard 1 of 4
cargo nextest run -E 'test(integration_)'      # filterset

Flags

FlagWhat it does
--profile <name>Use a profile from nextest.toml (e.g. ci)
--retries <n>Retry failing tests up to n times
--partition count:i/nRun shard i of n for parallel CI
--no-fail-fastRun all tests even after failures
-E <expr>Filterset expression to select tests
--workspaceRun tests across all workspace crates

In CI

Install with cargo install cargo-nextest --locked (or the prebuilt binary) and cache ~/.cargo plus target/. Define a ci profile that enables --retries for flaky tests and a JUnit reporter so the CI UI shows per-test results. nextest does not run doctests; keep a cargo test --doc step for those.

Common errors in CI

"error: no tests to run" means a filter or partition matched nothing, or the test binaries built but contain zero tests. "error: profile ci not found" means .config/nextest.toml is missing or lacks that profile. "the --doc flag is not supported" is a reminder that doctests still need cargo test.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →