@@ -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
387388extern crate adder;
@@ -394,8 +395,8 @@ fn it_works() {
394395```
395396
396397This 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.
399400This is also why ` tests ` is a suitable place to write integration-style tests:
400401they 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
428429Now we have three sections: our previous test is also run, as well as our new
429430one.
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+
431437That's all there is to the ` tests ` directory. The ` tests ` module isn't needed
432438here, since the whole thing is focused on tests.
433439
0 commit comments