Import tests directory outside of root crate?

I try to make the following file structure work:

my project
|
-- lib1 -- src -- file1.rs
|....................- file2.rs
| ...
-- lib2 -- src -- file1.rs
|...................- file2.rs
|
-- tests -- test-lib1.
.............- test-lib2.rs

how can i do this?
Or is this a bad style?
Do i have to use the #[path] attribute?

thanks for your effort

The Tokio repository does this for some of its tests. You can find the tests in the tests-integration folder.

1 Like

tokio has their tests in the "standard" tests directory next to the src directory.
Cargo searches for that by default, so that doesn't help me in any way and was not my question

I misunderstood what you were asking for.

It's possible to have a Cargo.toml with a src/ and tests/ folder in the project root together with the sub-library folders. However, this would associate the tests with a project defined in the root folder, and I'm pretty sure that you would need a src/ folder in the root too.

Another option that I think would work is to add the following to lib1/Cargo.toml for each test:

[[test]]
name = "lib1-tests"
path = "../tests/test-lib1.rs"

However this approach requires that you list every file in the tests folder separately.

1 Like

Thank you, this is a fine solution for me