Freedom251 › Unit Testing Frameworks
Rust libtest

What Rust libtest is
Rust libtest is the built-in Rust test harness for compiling and running a crate’s tests. Building with `rustc --test` links an executable to libtest; tests are free functions marked with `#[test]`. Cargo’s `cargo test` command handles building and running unit, integration, and documentation tests, with documentation examples run by default. The harness supports tests marked `#[should_panic]` and `#[ignore]`; ignored tests are compiled but skipped by default. You can filter tests by name or path, choose exact matches, skip matches, select ignored tests, or list tests and benchmarks without running them. Tests run concurrently by default, and `--test-threads` sets the thread count. Output can be captured, displayed for successful tests, or formatted as pretty, terse, or JSON. Rust libtest is free and supports Linux, macOS, and Windows. Catching panics requires the unwind strategy; abort-strategy support remains experimental. Benchmarking and custom harness support are also experimental or nightly-only, and the test crate’s support API is marked nightly-only and experimental.
Who it suits
It suits Rust developers who want to build and run crate tests through rustc or Cargo. It is also relevant to teams that need test filtering, output controls, or documentation tests as part of their workflow.
What it does well
- Built into Rust’s test harness and free.
- Cargo runs unit, integration, and documentation tests.
- Supports filtering, ignored tests, and test listing.
- Tests run in parallel by default.
- Supports Linux, macOS, and Windows.
What to know first
- Catching panics requires the unwind panic strategy.
- Benchmarks are unstable and nightly-only.
- Custom harness support is experimental and nightly-only.
- JSON output is unstable.
Limits
The test harness needs the unwind panic strategy to catch panics; abort-strategy support is experimental. Benchmarking and custom harnesses are experimental features available only on the nightly channel, and JSON output is unstable.
Plans
| Plan | Billed and limits | Price |
|---|---|---|
| Rust libtest | Built into Rust’s standard library test harness | Free |
As doc.rust-lang.org lists them, read 8 Oct 2026. The maker's own page has the final word.
Getting started
- Open the Rust test documentation website.
- Write test functions and mark them with `#[test]`.
- Build a test executable with `rustc --test`, or use Cargo’s `cargo test`.
- Use the harness filters, output options, or thread setting as needed.
Verdict
Rust libtest covers the core cycle of building, selecting, and running Rust tests, with Cargo providing an automatic route. Its benchmark and custom-harness options are not stable features.
Questions
Is Rust libtest free?
Yes. The Rust libtest plan is free.
Which platforms does it support?
It supports Linux, macOS, and Windows.
How does it work with Cargo?
Cargo’s `cargo test` builds and runs tests using libtest, including unit, integration, and documentation tests.
Are benchmarks available?
The `#[bench]` benchmark feature is unstable and available only on Rust’s nightly channel.
Is the test crate API stable?
The Rust test crate’s support API is marked nightly-only and experimental.
Can tests run in parallel?
Yes. Tests run in parallel by default, and `--test-threads` sets the thread count.
Facts from Rust libtest's own pages
- API stability
- The Rust test crate’s support API is marked nightly-only and experimental. · doc.rust-lang.org, 8 Oct 2026
- Benchmarking
- The #[bench] benchmark feature is unstable and available only on Rust’s nightly channel. · doc.rust-lang.org, 8 Oct 2026
- Benchmarks
- The harness supports `#[bench]` benchmarks, but benchmarks are unstable and available only on the nightly channel. · doc.rust-lang.org, 8 Oct 2026
- Cargo
- Cargo’s cargo test command handles building and running tests automatically. · doc.rust-lang.org, 8 Oct 2026
- Cargo integration
- Cargo's `cargo test` command builds and runs tests using libtest automatically. · doc.rust-lang.org, 8 Oct 2026
- Custom harnesses
- Experimental support for custom test harnesses is available on the nightly channel. · doc.rust-lang.org, 8 Oct 2026
- Documentation tests
- Cargo runs documentation tests by default by extracting code samples from library documentation comments and executing them. · doc.rust-lang.org, 8 Oct 2026
- Filtering
- Positional command-line arguments filter tests by substring in their full test-function path. · doc.rust-lang.org, 8 Oct 2026
- Harness
- Building with rustc --test links the executable with libtest, which handles running tests. · doc.rust-lang.org, 8 Oct 2026
- Listing
- The --list option prints tests and benchmarks without running them. · doc.rust-lang.org, 8 Oct 2026
- Output
- The harness can capture test output, show output from successful tests, and select pretty, terse, or JSON formats; JSON format is unstable. · doc.rust-lang.org, 8 Oct 2026
- Panic strategy limit
- Tests must use the unwind panic strategy to catch panics; abort-strategy support is experimental. · doc.rust-lang.org, 8 Oct 2026
- Parallel execution
- Tests run in parallel by default, and the thread count can be set with `--test-threads`. · doc.rust-lang.org, 8 Oct 2026
- Pass and fail
- A test passes when it returns without an error and fails when it panics or returns a non-zero termination result. · doc.rust-lang.org, 8 Oct 2026
- Purpose
- Rustc includes a built-in facility for building and running tests for a crate. · doc.rust-lang.org, 8 Oct 2026
- Results
- Tests pass when they return without an error and fail if they panic or return a non-zero termination result. · doc.rust-lang.org, 8 Oct 2026
- Test attributes
- The harness supports #[should_panic] tests and tests marked #[ignore], which are compiled but not run by default. · doc.rust-lang.org, 8 Oct 2026
- Test functions
- Tests are free functions marked with the `#[test]` attribute. · doc.rust-lang.org, 8 Oct 2026
- Test harness
- With `--test`, rustc links the executable with libtest, which handles running tests. · doc.rust-lang.org, 8 Oct 2026
- Test scope
- Cargo's test command compiles and executes unit, integration, and documentation tests. · doc.rust-lang.org, 8 Oct 2026
- Test selection
- The harness supports filtering tests by name, including exact matching, skipping matches, and selecting ignored tests. · doc.rust-lang.org, 8 Oct 2026
- Unstable options
- Unstable command-line options may not work correctly, break, or change, and require `-Z unstable-options`. · doc.rust-lang.org, 8 Oct 2026
Where Rust libtest stands on Freedom251
- Unit Testing Frameworks#24 of 32
