官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 武城县| 江门市| 福清市| 乐东| 宕昌县| 通榆县| 华安县| 河间市| 乌海市| 宣化县| 交城县| 赤峰市| 独山县| 岳阳市| 沈阳市| 百色市| 陆良县| 老河口市| 胶州市| 兴隆县| 武陟县| 玛纳斯县| 绥滨县| 伊宁市| 天全县| 河曲县| 陆川县| 开阳县| 新野县| 公安县| 博乐市| 长寿区| 连南| 隆化县| 九台市| 磐安县| 宜黄县| 营山县| 和平县| 嘉峪关市| 阿拉尔市|