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

  • Mastering Rust
  • Rahul Sharma Vesa Kaihlavirta
  • 138字
  • 2021-07-02 13:35:25

Ignoring tests

Another useful attribute for writing tests is #[ignore]. If your test code is exceedingly heavy, the #[ignore] annotation enables the test harness to ignore such test functions when running cargo test. You can then choose to individually run those tests by supplying an --ignored parameter to either your test runner or the cargo test command. Here's the code containing a silly loop that, when run using cargo test, is ignored by default:

// silly_loop.rs

pub fn silly_loop() {
for _ in 1..1_000_000_000 {};
}

#[cfg(test)]
mod tests {
#[test]
#[ignore]
pub fn test_silly_loop() {
::silly_loop();
}
}

Note the #[ignore] attribute over the test_silly_loop test function. Here's the output from the ignored test:

Note: A single test can also be run by supplying the test function name to Cargo, for example,  cargo test some_test_func.
主站蜘蛛池模板: 凤冈县| 巴彦县| 千阳县| 木里| 宣恩县| 苏尼特左旗| 即墨市| 尚义县| 错那县| 高密市| 龙胜| 泰兴市| 衡东县| 双鸭山市| 珠海市| 逊克县| 富川| 龙江县| 樟树市| 合阳县| 岫岩| 临高县| 青河县| 调兵山市| 蒙阴县| 治多县| 克什克腾旗| 东乌珠穆沁旗| 通许县| 高州市| 泾阳县| 秦安县| 鹿泉市| 布尔津县| 珲春市| 泰兴市| 敦化市| 盐山县| 黔南| 台北市| 安龙县|