- 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.
推薦閱讀
- Apache Spark 2.x Machine Learning Cookbook
- Android Application Development Cookbook(Second Edition)
- PostgreSQL Replication(Second Edition)
- 編程數學
- Visualforce Developer’s guide
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- C語言程序設計習題與實驗指導
- 計算機應用基礎項目化教程
- 3D Printing Designs:The Sun Puzzle
- Mastering Machine Learning with R
- Mastering Drupal 8
- Design Patterns and Best Practices in Java
- Python數據可視化之matplotlib實踐
- AI輔助編程Python實戰:基于GitHub Copilot和ChatGPT
- Getting Started with SpriteKit