Writing Automated Test in Rust

Sample Structure

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

#[test] annotation before the fn line: this attribute indicates this is a test function, so the test runner knows to treat this function as a test.

To run tests use

cargo test