January 2019
Beginner to intermediate
554 pages
13h 31m
English
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.rspub 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:
Read now
Unlock full access