rust-impl-testing
rust-impl-testing
The Rust testing skill: how to write unit tests, integration tests, and doc tests; how Cargo's three test kinds map to file layout; how to use #[should_panic], #[ignore], and Result<(), E>-returning tests; how to run async tests with #[tokio::test]; when to switch from cargo test to cargo nextest run; and how to add property, snapshot, and benchmark testing on stable Rust.
Cross-references: [[rust-impl-cargo-project]] (the [profile.test] profile, [dev-dependencies], the test and bench fields), [[rust-impl-async-tokio]] (#[tokio::test] runtime selection), [[rust-syntax-async-await]] (calling .await in test bodies).
When to use this skill
- User writes
#[test]functions, or wraps them in#[cfg(test)] mod tests { ... }. - User asks where integration tests go (
src/,tests/,examples/?). - User writes doc tests in
///comments and one of them stops compiling. - User wants negative tests via
#[should_panic]or wants to skip slow tests via#[ignore]. - User writes an
async fntest and gets a runtime panic. - User wants a faster runner than
cargo test, or per-test process isolation. - User wants property-based, snapshot, or micro-benchmark coverage on stable Rust.
For Cargo's project layout, [dev-dependencies], and the [profile.test] / [profile.bench] profiles, see [[rust-impl-cargo-project]]. For tokio runtime details under #[tokio::test], see [[rust-impl-async-tokio]].