23.7 Testing & Benchmarking
Cargo provides built-in support for testing and benchmarking. We’ll cover these in more detail in the next chapter. Here’s a quick preview:
23.7.1 cargo test
cargo test
Discovers and runs tests defined in:
tests/
folder (integration tests)- Any modules in
src/
annotated with#[cfg(test)]
(unit tests) - Documentation tests in your Rust doc comments
23.7.2 cargo bench
cargo bench
Runs benchmarks, typically set up with crates like criterion
for stable Rust.