So I have an integration test /tests/my_test.rs and a unit test in /src/some_module/function.rs. If I create a test helper in
/tests/test_helper.rs
pub struct TestHelper {
}
impl TestHelper {
fn meaning(&self) -> i32 {
42
}
}
I can figure out to use it in the /tests/my_test.rs
use super::test_helper::TestHelper;
#[test]
fn test_helper_works() {
let helper = TestHelper::new();
assert_eq!(helper.meaning(), 42);
}
But I cannot figure out how to access it from /src/some_module/function.rs in a mod tests block
#[cfg(test)]
mod tests {
use super::*;
use super::test_helper::TestHelper;
#[test]
fn some_old_test() {
let helper = TestHelper::new();
assert_eq!(helper.meaning(), 42);
}
}
I've tried putting the helper in /src/test_helpers/ using #[cfg(test)] but that allowed it in the unit tests but not the integration tests any way I could think to include it.
include!macro to include the helper source code in both places 2) unconditionally export the helper with#[doc(hidden)]#[path = "..."] mod utils;, or create a separate dev-dependency crate.