@@ -380,8 +380,9 @@ the `tests` directory.
380
380
381
381
# The ` tests ` directory
382
382
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:
385
386
386
387
``` rust,ignore
387
388
extern crate adder;
@@ -394,8 +395,8 @@ fn it_works() {
394
395
```
395
396
396
397
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.
399
400
This is also why ` tests ` is a suitable place to write integration-style tests:
400
401
they use the library like any other consumer of it would.
401
402
@@ -428,6 +429,11 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
428
429
Now we have three sections: our previous test is also run, as well as our new
429
430
one.
430
431
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
+
431
437
That's all there is to the ` tests ` directory. The ` tests ` module isn't needed
432
438
here, since the whole thing is focused on tests.
433
439
0 commit comments