mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Updated Note testsuite (markdown)
+8
-2
@@ -153,13 +153,19 @@ run-pass/cci_iter_exe.rs:
|
||||
|
||||
## Unit Tests
|
||||
|
||||
Most crates include <a href="https://github.com/mozilla/rust/wiki/Doc-unit-testing">unit tests</a> 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 <a href="https://github.com/mozilla/rust/wiki/Doc-unit-testing">unit tests</a> 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]
|
||||
|
||||
Reference in New Issue
Block a user