23.7 Testing and Benchmarking (Overview)
Cargo provides first-class support for running tests and benchmarks defined within your package’s crates, which are covered in detail in the next chapter.
cargo test: Discovers and runs tests annotated with#[test]within yoursrc/directory (unit tests), functions in thetests/directory (integration tests), and code examples in documentation comments (doc tests).cargo bench: Discovers and runs benchmarks annotated with#[bench]. Requires nightly Rust for the built-in harness; stable Rust typically uses external packages likecriterionfor benchmarking crates.