cargo-test
Run unit and integration tests
TLDR
Run all tests
SYNOPSIS
cargo test [options] [testname] [-- test-options]
DESCRIPTION
cargo test compiles and runs the test suite for a Rust project. It discovers unit tests (functions annotated with `#[test]` in `src/`), integration tests (files in `tests/`), documentation tests (code blocks in doc comments), and benchmark tests. A test name filter can be provided to run only matching tests.
Arguments after `--` are passed directly to the test harness rather than to Cargo. This allows controlling test execution behavior such as thread count, output capture, and whether ignored tests should run. Tests run in parallel by default; use `--test-threads=1` for sequential execution when tests have shared state.
PARAMETERS
--no-run
Compile without running--no-fail-fast
Run all tests regardless of failures--doc
Run documentation tests only--lib
Test library only--bins
Test all binaries--tests
Test all test targets--benches
Test all benchmarks--all-targets
Test all targets-p, --package spec
Test specified packages--workspace
Test all workspace members-j, --jobs n
Parallel build jobs--release
Test with release profile--features features
Enable features--all-features
Enable all features
TEST BINARY OPTIONS
-- --ignored
Run ignored tests-- --show-output
Show stdout from passing tests-- --test-threads n
Number of parallel test threads-- --nocapture
Don't capture test output
CAVEATS
Tests run in parallel by default. Use --test-threads=1 for sequential execution.
SEE ALSO
cargo(1), cargo-bench(1)
