cargo-nextest · a next-generation test runner for Rust

4 months ago

Your Rust test suite starts fast. Then it grows. cargo test runs the tests inside each binary together, and runs your binaries one after another, so a big workspace gets slow. And when something breaks, the output is a flat wall of text. Nextest is a next-generation test runner that fixes both.

Ask about this presentation

Chapters

  1. 0:00Slide 1
  2. 0:16See every test at a glance
  3. 0:30Install in one line
  4. 0:43Run your whole suite
  5. 1:07Why it is faster
  6. 1:28Built for real test suites
  7. 1:49One command to try it
Show transcript
  1. Your Rust test suite starts fast. Then it grows. cargo test runs the tests inside each binary together, and runs your binaries one after another, so a big workspace gets slow. And when something breaks, the output is a flat wall of text. Nextest is a next-generation test runner that fixes both.

    Slide text
    cargo- nextest

    A next-generation test runner for Rust.

    run in parallel → a line per test → built for CI
  2. Here is what nextest looks like. It runs each test in its own process, in parallel, and reports every result on its own line. Pass or fail, with the wall-clock time each test took in brackets, so you can see what passed, what failed, and what is slow at a glance.

    Slide text
    A real cargo nextest run: each test on its own line, marked PASS in green with its wall-clock time in brackets

    Each test on its own line · PASS or FAIL · with its wall-clock time.

  3. Getting it is one line. Grab the pre-built binary for your platform, no Rust compile needed. Or install it with cargo binstall, winget, or a Linux build. Once the binary is on your path, it works in any Cargo project.

    Slide text
    # macOS · a pre-built binary, no compile
    curl -LsSf https://get.nexte.st/latest/mac \
      | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin

    Or cargo binstall cargo-nextest, winget, or a Linux build · then run it in any Cargo project.

  4. Cd into any Cargo workspace and run cargo nextest run. It builds your tests and runs each one in its own process, in parallel. Every test gets a line: pass or fail, its timing, the binary it came from, and the test name. At the end, a one-line summary. Here, fourteen tests passed in twenty-one milliseconds. And it takes all the same flags as cargo test, so dash p to pick a package, or test-name filters, just work.

    Slide text
    $ cargo nextest run
        Starting 14 tests across 3 binaries (177 tests skipped)
            PASS [   0.005s] nextest-runner reporter::tests::no_capture_settings
            PASS [   0.004s] nextest-runner reporter::tests::test_final_warnings
            PASS [   0.004s] nextest-runner reporter::tests::test_progress_bar_prefix
            PASS [   0.014s] nextest-runner reporter::tests::test_write_skip_counts
         Summary [   0.021s] 14 tests run: 14 passed, 177 skipped

    Same flags as cargo test · -p my-package and test-name filters just work.

  5. Here is the difference. cargo test runs the tests in each binary together, and runs your binaries one after another. Nextest builds all the binaries up front, lists every test, then runs each individual test in its own process, in parallel. On larger workspaces that is up to about three times faster. And even when it is not faster, you still get the cleaner output and per-test timings to find your slow tests.

    Slide text
    Nextest's execution model: build every test binary, list every test, then run each test in its own process in parallel, collecting results and retrying as they finish

    Each test in its own process, run in parallel · up to ~3x faster on larger workspaces.

  6. And it is built for real test suites. There is a filterset language to run exactly the tests you want. Automatic retries for flaky tests, and a SLOW marker for anything over sixty seconds. For CI, you can archive your build once and split the tests across several machines, with JUnit XML output. By default it stops on the first failure, or you can tell it to run everything.

    Slide text
    • Precise selection · a filterset language to run exactly the tests you want.
    • Flaky tests · automatic retries, and a SLOW mark for anything over 60s.
    • CI at scale · archive the build once, split tests across machines.
    • Reports · JUnit XML, and stop-on-first-failure by default.
  7. That is nextest: run your whole suite in parallel, see every result at a glance, and wire it into CI. It takes the same flags as cargo test, so there is almost nothing to learn. Install it, then run cargo nextest run. The quickstart and every feature are in the docs.

    Slide text
    • Run in parallel · each test in its own process.
    • See it at a glance · a line per test, with timings.
    • Same flags · a drop-in for cargo test.
    • Built for CI · retries, partitioning, JUnit.

    cargo nextest run  ·  nexte.st

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York