Skip to content
Latchkey

How to Run Rust Tests in Parallel With nextest

cargo-nextest runs each test in its own process by default and can partition the suite across CI machines with --partition.

Install cargo-nextest, run cargo nextest run, and shard across machines with --partition count:i/n or hash:i/n.

Steps

  • Install with cargo install cargo-nextest or the setup action.
  • Run cargo nextest run for process-per-test parallelism.
  • Shard with --partition count:${{ matrix.shard }}/3.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3]
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/install-action@nextest
      - run: cargo nextest run --partition count:${{ matrix.shard }}/3

Gotchas

  • count: partitions by test count; hash: is stable across added tests.
  • Process-per-test isolates state but adds startup overhead for tiny tests.

Related guides

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