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

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.

主站蜘蛛池模板: 明光市| 双辽市| 白城市| 右玉县| 南漳县| 荆州市| 红安县| 桑日县| 兴仁县| 清水县| 平乡县| 河北省| 盐亭县| 烟台市| 喀喇沁旗| 贡山| 赤水市| 张家港市| 元氏县| 稻城县| 虞城县| 宁夏| 买车| 图们市| 峡江县| 邢台县| 义乌市| 仙居县| 唐海县| 芜湖市| 云梦县| 雷波县| 焉耆| 新密市| 开化县| 平安县| 延庆县| 牡丹江市| 西和县| 贵德县| 长白|