测试只有在lib中能够使用(cargo root lib)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| pub mod Dog { pub fn hello () { println!("wangwang"); } pub fn is_dog() -> bool { true } } pub mod Cat { pub fn hello () { println!("miaomiao"); } pub is_cat() -> bool { true } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| pub mod animal;
#[cfg(test)] mod tests { use crate::animal::Cat;
#[test] fn it_works() { assert_eq(2+2,4); } } #[test] fn use_cat () { assert_eq!(true,Cat::is_cat()); } #[test] fn use_dog() { assert_eq!(true,animal::Dog::is_dog()); }
|