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

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

主站蜘蛛池模板: 南京市| 辽阳县| 韶关市| 伊吾县| 定兴县| 县级市| 上高县| 乃东县| 连云港市| 遵义县| 公主岭市| 东安县| 电白县| 西乌| 邹城市| 榆林市| 琼中| 长岛县| 泰安市| 安仁县| 榕江县| 博湖县| 宁夏| 崇明县| 五常市| 昌黎县| 武威市| 扶绥县| 丹江口市| 舒城县| 神木县| 鸡东县| 博乐市| 龙岩市| 南开区| 乌兰浩特市| 仁化县| 新乐市| 天长市| 富蕴县| 宁武县|