Skip to content

Commit ffcd4d8

Browse files
authored
Suggest using mod.rs pattern to share test code (#1577)
This brings the information inline with how it's presented in the Rust book[1] with regarding on how to structure common/shared code in integration tests. [1] https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests
1 parent ee688e4 commit ffcd4d8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/testing/integration_testing.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ running 0 tests
4747
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
4848
```
4949

50-
Each Rust source file in the `tests` directory is compiled as a separate crate. One
51-
way of sharing some code between integration tests is making a module with public
50+
Each Rust source file in the `tests` directory is compiled as a separate crate. In
51+
order to share some code between integration tests we can make a module with public
5252
functions, importing and using it within tests.
5353

54-
File `tests/common.rs`:
54+
File `tests/common/mod.rs`:
5555

5656
```rust,ignore
5757
pub fn setup() {
@@ -74,8 +74,9 @@ fn test_add() {
7474
}
7575
```
7676

77-
Modules with common code follow the ordinary [modules][mod] rules, so it's ok to
78-
create common module as `tests/common/mod.rs`.
77+
Creating the module as `tests/common.rs` also works, but is not recommended
78+
because the test runner will treat the file as a test crate and try to run tests
79+
inside it.
7980

8081
[unit]: unit_testing.md
8182
[mod]: ../mod.md

0 commit comments

Comments
 (0)