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

  • 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.

主站蜘蛛池模板: 阳山县| 苏州市| 永兴县| 灌南县| 巴林右旗| 盈江县| 九江县| 亚东县| 霍州市| 饶平县| 哈巴河县| 花垣县| 清新县| 水富县| 元江| 英超| 台东县| 永清县| 中阳县| 平潭县| 长葛市| 台山市| 怀集县| 毕节市| 隆子县| 哈密市| 凤阳县| 丰台区| 历史| 疏勒县| 炉霍县| 荆州市| 深州市| 凤庆县| 电白县| 榆树市| 宣威市| 常熟市| 泰兴市| 环江| 兴山县|