May 2019
Intermediate to advanced
698 pages
17h 21m
English
There are also test cases where you will want your API methods to fail based on some input, and you want the test framework to assert this failure. Rust provides an attribute called #[should_panic] for this. Here's a test that panics and uses this attribute:
// panic_test.rs#[test]#[should_panic]fn this_panics() { assert_eq!(1, 2);}
The #[should_panic] attribute can be paired with a #[test] attribute to signify that running the this_panics function should cause a non-recoverable failure, which is called a panic in Rust.
Read now
Unlock full access