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

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.
主站蜘蛛池模板: 扬州市| 西藏| 巴塘县| 开江县| 文安县| 临夏市| 西华县| 天等县| 始兴县| 长子县| 英山县| 全椒县| 九龙县| 江阴市| 佳木斯市| 元谋县| 安宁市| 嵩明县| 无为县| 依兰县| 武义县| 鸡泽县| 和龙市| 丰城市| 泰和县| 安远县| 广河县| 曲阜市| 城步| 东山县| 黑水县| 霸州市| 通山县| 方正县| 大足县| 吕梁市| 星子县| 清水河县| 永嘉县| 汉中市| 乡宁县|