Rust

Faster Testing with nextest

Run Rust tests in parallel with cargo-nextest for dramatically faster feedback loops

Faster Testing with cargo-nextest

cargo test runs tests sequentially within each test binary. For projects with hundreds of tests, that means waiting. cargo-nextest runs each test as a separate process in parallel, cutting feedback time dramatically.

Installation

Pre-built binaries (recommended — compiling from source can fail due to nightly dependencies):

# macOS (Apple Silicon or Intel)
curl -LsSf https://get.nexte.st/latest/mac | tar xzf - -C ~/.cargo/bin

# Linux x86_64
curl -LsSf https://get.nexte.st/latest/linux | tar xzf - -C ~/.cargo/bin

Verify:

cargo nextest --version
# cargo-nextest 0.9.128

Basic Usage

Drop-in replacement for cargo test:

# Run all tests
cargo nextest run

# Filter by test name
cargo nextest run noise_figure

# Run tests in a specific package (workspace)
cargo nextest run -p rfconversions

# List tests without running
cargo nextest list

The output is cleaner than cargo test — each test gets a PASS/FAIL line with timing:

        PASS [   0.005s] rfconversions::tests cascade_noise_factor_two_stages
        PASS [   0.006s] rfconversions::tests db_to_linear_zero
        PASS [   0.004s] rfconversions::tests frequency_to_wavelength_roundtrip
────────────
     Summary [   0.083s] 114 tests run: 114 passed, 0 skipped

Real-World Benchmarks

Performance across five RF engineering crates (720 tests total):

CrateTestscargo testcargo nextest runSpeedup
rfconversions1148.1s0.2s40×
touchstone152~4s0.4s10×
gainlineup122~3s0.5s
linkbudget196~5s0.4s12×
regulatory-rf136~8s2.6s
Total720~28s~4.1s~7×

The biggest gains come from crates with many small, independent tests. Crates with inherently slow tests (Monte Carlo simulations in regulatory-rf) are bottlenecked by the slowest individual test regardless of parallelism.

The Doctest Gap

Important: nextest does not run doctests. If your crates use doc-tests extensively (and they should — they serve as both documentation and regression tests), you need both:

# Fast parallel unit + integration tests
cargo nextest run

# Doctests (still sequential)
cargo test --doc

Combine them in a Just recipe for complete coverage:

# Full test suite: nextest for speed + doctests for completeness
test-full:
    cargo nextest run
    cargo test --doc

Configuration

Create .config/nextest.toml in your project root:

[profile.default]
# Stop on first failure (good for local dev)
fail-fast = true

# Retry flaky tests (useful in CI)
retries = 0

# Kill tests that take too long
slow-timeout = { period = "60s", terminate-after = 2 }

[profile.ci]
# CI profile: don't fail fast, retry once
fail-fast = false
retries = 1

Use profiles:

cargo nextest run --profile ci

Multi-Crate Workspace Script

For repos spread across multiple directories (not a Cargo workspace):

#!/usr/bin/env bash
# test-fast.sh — run nextest across all crates
set -euo pipefail

CRATES=(rfconversions touchstone gainlineup linkbudget regulatory-rf)
TOTAL=0
FAILED=0

for crate in "${CRATES[@]}"; do
    echo "=== $crate ==="
    cd ~/Development/"$crate"
    if cargo nextest run 2>&1; then
        ((TOTAL++))
    else
        ((FAILED++))
    fi
done

echo ""
echo "Results: $((TOTAL)) passed, $FAILED failed out of ${#CRATES[@]} crates"

When to Use What

ScenarioTool
Fast feedback during developmentcargo nextest run
CI (full coverage)cargo nextest run && cargo test --doc
Debugging with print outputcargo test -- --nocapture
Running specific doctests onlycargo test --doc specific_fn
Flaky test detectioncargo nextest run --retries 3

See Also