Skip to content

Commit

Permalink
Ch. 11: use scope tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Apr 18, 2024
1 parent 0e9980e commit 076420c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use adder::add_two;

#[test]
fn it_adds_two() {
assert_eq!(4, adder::add_two(2));
assert_eq!(4, add_two(2));
}
5 changes: 5 additions & 0 deletions src/ch11-03-test-organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file:
<span class="caption">Listing 11-13: An integration test of a function in the
`adder` crate</span>

Each file in the `tests` directory is a separate crate, so we need to bring our
library into each test crate’s scope. For that reason we add `use
adder::add_two` at the top of the code, which we didn’t need in the unit
tests.

We don’t need to annotate any code in *tests/integration_test.rs* with
`#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files
in this directory only when we run `cargo test`. Run `cargo test` now:
Expand Down

0 comments on commit 076420c

Please sign in to comment.