77 cargo test [options] [testname] [-- test-options]
88
99DESCRIPTION
10- Compile and execute unit and integration tests.
10+ Compile and execute unit, integration, and documentation tests.
1111
1212 The test filtering argument TESTNAME and all the arguments following the
1313 two dashes (--) are passed to the test binaries and thus to libtest
@@ -23,20 +23,34 @@ DESCRIPTION
2323
2424 cargo test foo -- --test-threads 3
2525
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.
3134
3235 The libtest harness may be disabled by setting harness = false in the
3336 target manifest settings, in which case your code will need to provide
3437 its own main function to handle running tests.
3538
39+ Documentation tests
3640 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.
4054
4155OPTIONS
4256 Test Options
@@ -116,9 +130,9 @@ OPTIONS
116130 the library in the manifest.
117131
118132 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
122136 <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
123137 is set when the integration test is built so that it can use the env
124138 macro <https://doc.rust-lang.org/std/macro.env.html> to locate the
0 commit comments