ref: https://stackoverflow.com/questions/54585804/how-to-run-a-specific-unit-test-in-rust
1rustc --test <file>
This generates a binary file. Then if you run the binary file, all tests will be conducted. Source code format be like:
1#[cfg(test)]2mod tests {3 use super::*;4
5 #[test]6 fn test_tuple_out_of_range_positive() {7 assert_eq!(8 Color::try_from((256, 1000, 10000)),9 Err(IntoColorError::IntConversion)10 );11 }
To run a specific test, run:
1./xxx --exact test::test_tuple_out_of_range_positive
Cargo way
1cargo test test_fn_name # filters with test_fn_name2cargo test test_fn_name -- --exact3cargo test test_mod_name::test_fn_name -- --exact4cargo test --package school_info repeat_students_should_not_get_full_marks -- --exact5# To show output6cargo test --package py-like --test io -- tests::main --exact --nocapture7# test1() in helper.rs8cargo test helper::test1 -- --exact