23.14 Testing
Testing
Overview
Rust provides a built-in testing framework to write and run unit tests.
Topics
- Writing Unit Tests
- Using
#[test]Attribute - Running Tests with
cargo test
Examples
fn add(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
assert_eq!(add(2, 3), 5);
}
}