Skip to content

Commit ee78a02

Browse files
committed
Rollup merge of #34060 - JDemler:master, r=steveklabnik
Improved documentation for tests/ directory This ambigouity problem was already discussed in the [forums](https://users.rust-lang.org/t/problem-using-external-modules-inside-integration-test-submodule/5312/6).
2 parents 4225744 + c26703b commit ee78a02

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/doc/book/testing.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ the `tests` directory.
380380

381381
# The `tests` directory
382382

383-
To write an integration test, let's make a `tests` directory, and
384-
put a `tests/lib.rs` file inside, with this as its contents:
383+
Each file in `tests/*.rs` directory is treated as individual crate.
384+
So, to write an integration test, let's make a `tests` directory, and
385+
put a `tests/integration_test.rs` file inside, with this as its contents:
385386

386387
```rust,ignore
387388
extern crate adder;
@@ -394,8 +395,8 @@ fn it_works() {
394395
```
395396

396397
This looks similar to our previous tests, but slightly different. We now have
397-
an `extern crate adder` at the top. This is because the tests in the `tests`
398-
directory are an entirely separate crate, and so we need to import our library.
398+
an `extern crate adder` at the top. This is because each test in the `tests`
399+
directory is an entirely separate crate, and so we need to import our library.
399400
This is also why `tests` is a suitable place to write integration-style tests:
400401
they use the library like any other consumer of it would.
401402

@@ -428,6 +429,11 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
428429
Now we have three sections: our previous test is also run, as well as our new
429430
one.
430431

432+
Cargo will ignore files in subdirectories of the `tests/` directory.
433+
Therefore shared modules in integrations tests are possible.
434+
For example `tests/common/mod.rs` is not seperatly compiled by cargo but can
435+
be imported in every test with `mod common;`
436+
431437
That's all there is to the `tests` directory. The `tests` module isn't needed
432438
here, since the whole thing is focused on tests.
433439

0 commit comments

Comments
 (0)