知识卡片
测试函数及运行报告
在函数上标 #[test],测试运行器才会把它当作测试执行。普通的准备函数由用例调用。断言失败导致 panic 时,测试会显示 FAILED,报告给出失败详情和用例名。读汇总时要区分失败、标记忽略与筛选排除。
相关卡片 [[筛选或略过测试]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 编写自动化测试 The Anatomy of a Test Function · 查看原书依据
At its simplest, a test in Rust is a function that’s annotated with the test attribute. Attributes are metadata about pieces of Rust code; one example is the derive attribute we used with structs in Chapter 5. To change a function into a test function, add #[test] on the line before fn.
参考来源
- 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0015)
- 结论依据:原文把 `#[test]` 与 `cargo test` 所构建的测试运行器联系起来。
- 原始内容:At its simplest, a test in Rust is a function that’s annotated with the test attribute. Attributes are metadata about pieces of Rust code; one example is the derive attribute we used with structs in Chapter 5. To change a function into a test function, add #[test] on the line before fn.