You can import from your modules #[cfg(test)] from other modules #[cfg(test)] , therefore, for example, in main.rs or in some other module you can do something like:
#[cfg(test)] pub mod test_util { pub fn return_two() -> usize { 2 } }
and then from anywhere else in your project:
#[cfg(test)] mod test { use crate::test_util::return_two; #[test] fn test_return_two() { assert_eq!(return_two(), 2); } }
source share