I'd like to split my integration tests into multiple files (because it's getting long). This can be easily done:
/tests/
/data/ // <- dataset for testing
a_tests.rs // <- this contains "common" functions which I'd like to use in b_tests.rs
b_tests.rs
However, a_tests.rs
contains some functions which I'd like to use in b_tests.rs
. For example a common Lazy once_cell which reads the data file only once. And also a fn common_func(_)
which does assertion based on numerical comparisons of the results.
So how do I import objects from a_tests.rs
in b_tests.rs
?
CodePudding user response:
Per the Rust documentation on integration tests each file in the tests
directory is compiled into a separate crate, but:
Files in subdirectories of the tests directory don’t get compiled as separate crates or have sections in the test output. So you can have this file structure:
/tests/
/common/
mod.rs
/data/
a_tests.rs
b_tests.rs
Then move your shared functions from a_tests.rs
into common/mod.rs
and you can import them into a_tests.rs
and b_tests.rs
via mod common;