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

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.
主站蜘蛛池模板: 商丘市| 扶沟县| 沛县| 涟源市| 襄汾县| 朝阳县| 长汀县| 太康县| 安阳市| 佳木斯市| 淅川县| 万安县| 东辽县| 囊谦县| 开化县| 长垣县| 安远县| 灌云县| 勐海县| 北川| 喜德县| 大邑县| 湖州市| 旬邑县| 洞头县| 永寿县| 抚松县| 井研县| 丰原市| 邓州市| 师宗县| 葵青区| 和龙市| 八宿县| 巨鹿县| 行唐县| 霍山县| 尉氏县| 潢川县| 浙江省| 丰城市|