- 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.
推薦閱讀
- 高手是如何做產(chǎn)品設(shè)計的(全2冊)
- Java Web程序設(shè)計
- Learn Programming in Python with Cody Jackson
- HTML5 and CSS3 Transition,Transformation,and Animation
- 名師講壇:Java微服務(wù)架構(gòu)實戰(zhàn)(SpringBoot+SpringCloud+Docker+RabbitMQ)
- RabbitMQ Cookbook
- ArcGIS for Desktop Cookbook
- SQL Server 2008 R2數(shù)據(jù)庫技術(shù)及應(yīng)用(第3版)
- Python網(wǎng)絡(luò)爬蟲技術(shù)與應(yīng)用
- Mastering Adobe Captivate 7
- 貫通Tomcat開發(fā)
- Java7程序設(shè)計入門經(jīng)典
- 交互設(shè)計師成長手冊:從零開始學(xué)交互
- Node.js 6.x Blueprints
- Monitoring Docker