I have the following code defining a path where generated files can be placed:
fn gen_test_dir() -> tempdir::TempDir {
What I do is put my unit tests with any other utilities into a submodule protected with #[cfg(test)]:
#[cfg(test)]
mod tests { // The contents could be a separate file if it helps organisation
// Not a test, but available to tests.
fn some_utility(s: String) -> u32 {
...
}
#[test]
fn test_foo() {
assert_eq!(...);
}
// more tests
}