Testing, Clippy & Rustdoc
Prev: Cargo, Workspaces & Profiles | Up: cargo_and_tooling | Next: tutorials
Rel: Testing & Maintainability
Ref: The Rust Book — Writing Automated Tests
Tags: #public #prog #rust #tooling #testing
Contents
Unit Tests & Doc-Tests
Place unit tests in a #[cfg(test)] mod tests block inside the same file (compiled out of release binaries), and executable examples inside /// doc comments:
/// Doubles an integer.
///
/// ```
/// assert_eq!(my_crate::double(21), 42);
/// ```
pub fn double(x: i32) -> i32 {
x * 2
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn doubles_negative() {
assert_eq!(double(-3), -6);
}
}
Standard Quality Commands
cargo test # Unit, integration, and doc tests
cargo clippy --all-targets -- -D warnings
cargo fmt --check
cargo doc --no-deps --open
Linked from
Related notes
- tuts/rust/cargo_and_tooling Linked here; links to this page; shared tags: #prog, #rust, #tooling
- tuts/rust/cargo_and_tooling/cargo_workspaces_and_profiles Linked here; links to this page; shared tags: #prog, #rust, #tooling
- tuts/programming/software_design/testing_and_maintainability Linked here; shared tags: #prog, #testing
- tuts/rust/tutorials Linked here; shared tags: #prog, #rust
- tuts/interop/rust_and_python_pyo3_maturin shared tags: #prog, #rust
- tuts/rust shared tags: #prog, #rust
- tuts/rust/builtins shared tags: #prog, #rust
- tuts/rust/builtins/Clone shared tags: #prog, #rust
- tuts/rust/builtins/Copy shared tags: #prog, #rust
- tuts/rust/builtins/Drop shared tags: #prog, #rust