How to organize integration tests like a lib crate


Usually I would do this in a

extern some_crate

pub mod some_submodule;

Then in a separate file;, I could do this

use some_crate::some;

Can’t seem to get the same thing working in a tests/ directory for my crate. Cargo test requires me to put extern some_crate in each and every test file. I want them all to share a common imported namespace. Furthermore, I can’t seem to figure out how to use a module in separate file in the tests directory. The compiler wants me to extern crate any file I try to use from another file.


Yeah, each test file is compiled as a separate executable that uses your library as an external crate. This exposes only public interface of your library.

If you want to test something in a private module, you’ll need to put #[test] functions in that private module, not in tests/ directory.