diff --git a/Note-testsuite.md b/Note-testsuite.md index d843e38..2f7804e 100644 --- a/Note-testsuite.md +++ b/Note-testsuite.md @@ -153,13 +153,19 @@ run-pass/cci_iter_exe.rs: ## Unit Tests -Most crates include unit tests which are part of the crate they test. These crates are built with the --test flag and run as part of `make check`. +Most crates include unit tests which are part of the crate they test. These crates are built with the --test` flag and run as part of `make check`. -Tests should go near the code they test. If a module's tests require additional helper functions then they should be enclosed in a conditionally-compiled test module: +All tests in a module should go in an inner module named `test`, with the attribute `#[cfg(test)]`. Placing tests in their own module is a practical issue - because test cases are not included in normal builds, building with `--test` require a different set of imports than without, and that causes 'unused import' errors. ``` +use std::option; + +fn do_something() { ... } + #[cfg(test)] mod test { + use std::vec; + fn helper_fn() { ... } #[test]