23.14 Testing

Testing

Overview

Rust provides a built-in testing framework to write and run unit tests.

Topics

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);
    }
}

Tags

#rust #testing #unittests