|
1.
|
|
|
% The Rust Testing Guide
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:2
|
|
2.
|
|
|
# Quick start
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:4
|
|
3.
|
|
|
To create test functions, add a `#[test]` attribute like this:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:6
|
|
4.
|
|
|
~~~test_harness
fn return_two() -> int {
2
}
|
|
|
type: Plain text
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:11
|
|
5.
|
|
|
#[test]
fn return_two_test() {
let x = return_two();
assert!(x == 2);
}
~~~
|
|
|
type: Plain text
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:18
|
|
6.
|
|
|
To run these tests, compile with `rustc --test` and run the resulting binary:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:21
|
|
7.
|
|
|
~~~console $ rustc --test foo.rs $ ./foo running 1 test test return_two_test ... ok
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:27
|
|
8.
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ~~~
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:30
|
|
9.
|
|
|
`rustc foo.rs` will *not* compile the tests, since `#[test]` implies `#[cfg(test)]`. The `--test` flag to `rustc` implies `--cfg test`.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:33
|
|
10.
|
|
|
# Unit testing in Rust
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-testing.md:36
|