Skip to content
Latchkey

cargo test --workspace: Test Every Crate in CI

cargo test --workspace runs the test suites of every package in the workspace, not just the current one.

In a multi-crate repo, plain cargo test only covers the current package. --workspace plus --all-features is the usual CI gate so nothing slips through unbuilt.

What it does

cargo test --workspace builds and runs unit tests, integration tests, and documentation tests for all members of the workspace. Test arguments after a bare -- are forwarded to the test harness (libtest), not to cargo.

Common usage

Terminal
cargo test --workspace --all-features --locked
cargo test --workspace --no-fail-fast        # run all crates even if one fails
cargo test -p mycrate -- --nocapture         # show println! output
cargo test --workspace --doc                 # only doctests

Flags

FlagWhat it does
--workspaceTest all packages in the workspace
--all-featuresEnable every feature of every crate
--no-fail-fastRun all test binaries even after one fails
--no-default-featuresDisable default features
-- --nocaptureForward --nocapture to libtest to show stdout
-- --test-threads=1Run tests serially (forwarded to libtest)

In CI

Use --no-fail-fast so a single failing crate does not hide failures elsewhere, and cache ~/.cargo plus target/ keyed on Cargo.lock. Doctests rebuild crates, so they can dominate runtime; split --doc into its own step if needed.

Common errors in CI

"error: no test target named ..." means the --test <name> you passed does not match a file in tests/. "error: unexpected argument '--nocapture'" means you forgot the -- separator; libtest flags must come after it. "test failed, to rerun pass -p mycrate --lib" is cargo telling you exactly which target to rerun locally.

Related guides

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