- 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.
推薦閱讀
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- 劍指Offer(專項(xiàng)突破版):數(shù)據(jù)結(jié)構(gòu)與算法名企面試題精講
- Web Scraping with Python
- Learning Elixir
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優(yōu)化計算
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- Java EE 7 Performance Tuning and Optimization
- Unreal Engine 4 Shaders and Effects Cookbook
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- Windows Phone 7.5:Building Location-aware Applications
- Python算法指南:程序員經(jīng)典算法分析與實(shí)現(xiàn)
- jQuery Mobile移動應(yīng)用開發(fā)實(shí)戰(zhàn)(第3版)
- 愛上micro:bit
- Node Cookbook(Second Edition)
- OpenCV with Python Blueprints