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

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.
主站蜘蛛池模板: 鄂伦春自治旗| 沛县| 尚志市| 会东县| 华宁县| 那曲县| 财经| 乐东| 巴塘县| 鹿邑县| 宜丰县| 准格尔旗| 明星| 彭泽县| 常山县| 隆化县| 普宁市| 葫芦岛市| 南安市| 图木舒克市| 汉阴县| 石狮市| 安龙县| 友谊县| 凌云县| 大兴区| 团风县| 赤城县| 获嘉县| 瓮安县| 英吉沙县| 祁东县| 永德县| 福安市| 新沂市| 夏津县| 武冈市| 水城县| 搜索| 军事| 汕头市|