Rust 程序设计语言 简体中文版 1.85.0
assert_eq!(result, 4); 222/562Rust 程序设计语言 简体中文版 } #[test] fn another() { panic!("Make this test fail"); } } 示例 11-3:增加第二个因调用了 panic! 而失败的测试 再次 cargo test 运行测试。输出应该看起来像示例 11-4,它表明 failures: ---- tests::another stdout ---- thread 'tests::another' panicked at src/lib.rs:17:9: Make this test fail note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: 了。在单独测试结果和摘要之间多了两个新 的部分:第一个部分显示了测试失败的详细原因。在这个例子中,我们看到 another 因为在 src/lib.rs 的第 10 行 panicked at 'Make this test fail' 而失败的详细信息。下一部分列出 了所有失败的测试,这在有很多测试和很多失败测试的详细输出时很有帮助。我们可以通过使 用失败测试的名称来只运行这个测试,以便调试;下一部分0 码力 | 562 页 | 3.23 MB | 8 天前3
共 1 条
- 1