知识卡片
断言约定并输出上下文
若问候语的契约只要求保留姓名,检查 result.contains(name) 就能覆盖约定,前缀可自由变化。assert!、assert_eq! 和 assert_ne! 接受附加格式化消息,失败时可说明所检查的约定并显示实际输出。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 编写自动化测试 Checking Results with the assert! Macro · 查看原书依据
You can also add a custom message to be printed with the failure message as optional arguments to the assert!, assert_eq!, and assert_ne! macros. Any arguments specified after the required arguments are passed along to the format! macro (discussed in “Concatenation with the + Operator or the format! Macro” on page 149), so you can pass a format string that contains {} placeholders and values to go in those placeholders.
参考来源
- 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0089)
- 结论依据:原文说明附加参数遵循 `format!`,并用问候语丢失姓名演示诊断价值。
- 原始内容:You can also add a custom message to be printed with the failure message as optional arguments to the assert!, assert_eq!, and assert_ne! macros. Any arguments specified after the required arguments are passed along to the format! macro (discussed in “Concatenation with the + Operator or the format! Macro” on page 149), so you can pass a format string that contains {} placeholders and values to go in those placeholders.