From 0e9980e4295df3462b26f8c42547d6cb906c86ab Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 30 Jul 2022 14:38:08 +0200 Subject: [PATCH 1/2] Unnecessary import removal As per my observations crate being subject to integration tests is available for qualified reference without importing it with `use`. --- .../listing-11-13/tests/integration_test.rs | 2 -- src/ch11-03-test-organization.md | 4 ---- 2 files changed, 6 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index e26fa71096..336c5ec54b 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -1,5 +1,3 @@ -use adder; - #[test] fn it_adds_two() { assert_eq!(4, adder::add_two(2)); diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 9f26546cf4..61eda50c49 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -117,10 +117,6 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: Listing 11-13: An integration test of a function in the `adder` crate -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` 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: From 076420ce2098031d6bbad5d88768511c3ed91504 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 18 Apr 2024 12:03:45 -0600 Subject: [PATCH 2/2] Ch. 11: `use` scope tweak --- .../listing-11-13/tests/integration_test.rs | 4 +++- src/ch11-03-test-organization.md | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index 336c5ec54b..3822d6b976 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -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)); } diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 61eda50c49..918945780a 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -117,6 +117,11 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: Listing 11-13: An integration test of a function in the `adder` crate +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: