官术网_书友最值得收藏!

Running tests

The way we run this test is by compiling our code in test mode. The compiler ignores the compilation of test annotated functions unless it's told to build in test mode. This can be achieved by passing the --test flag to rustc when compiling the test code. Following that, tests can be run by simply executing the compiled binary. For the preceding test, we'll compile it in test mode by running this:

rustc --test first_unit_test.rs

With the --test flag, rustc puts a main function with some test harness code and invokes all your defined test functions as threads in parallel. All tests are run in parallel by default unless told to do so with the environment variable RUST_TEST_THREADS=1. This means that if we want to run the preceding test in single thread mode, we can execute with RUST_TEST_THREADS=1 ./first_unit_test.

Now, Cargo already has support for running tests, and all of this is usually done internally by invoking cargo test. This command compiles and runs the test annotated functions for us. In the examples that follow, we will mostly use Cargo to run our tests.

主站蜘蛛池模板: 北碚区| 勐海县| 堆龙德庆县| 城市| 临桂县| 咸宁市| 同江市| 夏河县| 会泽县| 沾益县| 金阳县| 奉化市| 南华县| 青铜峡市| 嘉鱼县| 东安县| 武隆县| 商南县| 育儿| 太原市| 宜兰市| 乐平市| 通榆县| 衡阳县| 奉化市| 于都县| 青浦区| 城口县| 五常市| 邢台县| 乐东| 怀仁县| 临潭县| 平塘县| 万盛区| 邓州市| 荣成市| 大庆市| 台湾省| 民勤县| 华安县|