- Mastering Rust
- Rahul Sharma Vesa Kaihlavirta
- 87字
- 2021-07-02 13:35:25
Failing tests
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.
推薦閱讀
- Node.js+Webpack開發實戰
- Spring 5企業級開發實戰
- Visual C++數字圖像模式識別技術詳解
- 面向對象程序設計(Java版)
- Flux Architecture
- Extreme C
- 快速入門與進階:Creo 4·0全實例精講
- Node.js 12實戰
- R Data Science Essentials
- 智能手機故障檢測與維修從入門到精通
- Mastering Adobe Captivate 7
- jQuery for Designers Beginner's Guide Second Edition
- Software Development on the SAP HANA Platform
- 自己動手構建編程語言:如何設計編譯器、解釋器和DSL
- TypeScript High Performance