7
7
cargo test [options] [testname] [-- test-options]
8
8
9
9
DESCRIPTION
10
- Compile and execute unit and integration tests.
10
+ Compile and execute unit, integration, and documentation tests.
11
11
12
12
The test filtering argument TESTNAME and all the arguments following the
13
13
two dashes (--) are passed to the test binaries and thus to libtest
@@ -23,20 +23,34 @@ DESCRIPTION
23
23
24
24
cargo test foo -- --test-threads 3
25
25
26
- Tests are built with the --test option to rustc which creates an
27
- executable with a main function that automatically runs all functions
28
- annotated with the #[test] attribute in multiple threads. #[bench]
29
- annotated functions will also be run with one iteration to verify that
30
- they are functional.
26
+ Tests are built with the --test option to rustc which creates a special
27
+ executable by linking your code with libtest. The executable
28
+ automatically runs all functions annotated with the #[test] attribute in
29
+ multiple threads. #[bench] annotated functions will also be run with one
30
+ iteration to verify that they are functional.
31
+
32
+ If the package contains multiple test targets, each target compiles to a
33
+ special executable as aforementioned, and then is run serially.
31
34
32
35
The libtest harness may be disabled by setting harness = false in the
33
36
target manifest settings, in which case your code will need to provide
34
37
its own main function to handle running tests.
35
38
39
+ Documentation tests
36
40
Documentation tests are also run by default, which is handled by
37
- rustdoc. It extracts code samples from documentation comments and
38
- executes them. See the rustdoc book <https://doc.rust-lang.org/rustdoc/>
39
- for more information on writing doc tests.
41
+ rustdoc. It extracts code samples from documentation comments of the
42
+ library target, and then executes them.
43
+
44
+ Different from normal test targets, each code block compiles to a
45
+ doctest executable on the fly with rustc. These executables run in
46
+ parallel in separate processes. The compilation of a code block is in
47
+ fact a part of test function controlled by libtest, so some options such
48
+ as --jobs might not take effect. Note that this execution model of
49
+ doctests is not guaranteed and may change in the future; beware of
50
+ depending on it.
51
+
52
+ See the rustdoc book <https://doc.rust-lang.org/rustdoc/> for more
53
+ information on writing doc tests.
40
54
41
55
OPTIONS
42
56
Test Options
@@ -116,9 +130,9 @@ OPTIONS
116
130
the library in the manifest.
117
131
118
132
Binary targets are automatically built if there is an integration test
119
- or benchmark. This allows an integration test to execute the binary to
120
- exercise and test its behavior. The CARGO_BIN_EXE_<name> environment
121
- variable
133
+ or benchmark being selected to test . This allows an integration test to
134
+ execute the binary to exercise and test its behavior. The
135
+ CARGO_BIN_EXE_<name> environment variable
122
136
<https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
123
137
is set when the integration test is built so that it can use the env
124
138
macro <https://doc.rust-lang.org/std/macro.env.html> to locate the
0 commit comments