Testing

Rust supports unit testing, documentation testing, and integration testing.

Unit Testing

main.rs

fn main() { println!("10 + 5 is {}", add(10, 5)); } fn add(first_number: i32, second_number: i32) -> i32 { return first_number + second_number; } #[cfg(test)] mod tests;

tests.rs

use super::*; #[test] fn test_add() { assert_eq!(add(10, 5), 15); }

Running cargo test in the project root directory will invoke all of the test functions, and display the results.