知识卡片
按行为风险分配宏测试
宏测试先验证一条真实、应成功的调用路径。输入限制和错误消息是接口的一部分时,加入编译失败样例。在调用端可以观察行为的地方,黑盒断言通常更容易准备,输出小改也较少影响测试。复杂 AST 变换或难以定位的故障,可直接测试关键的内部函数。对参与外部系统交互的生成代码,还要验证真正的边界,例如在数据库上确认生成的持久化逻辑。
相关卡片 [[白盒断言宏展开输出]]、[[黑盒验证宏的调用行为]]、[[编译失败测试核对诊断]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Testing a builder macro 测试失败阶段并选择粒度 · 查看原书依据
That being said, white-box testing for macros is a lot of work. Creating the in- and outputs of helper functions, like the ones in this chapter, is cumbersome. (I am excluding functions that have no macro-specific inputs or outputs from this discussion. For that category, see the brief discussion in the previous paragraph.) In a large project, such tests can help you catch bugs early on.
参考来源
- 位置:《Write Powerful Rust Macros》第06章《Testing a builder macro》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-6.xhtml#p150)
- 结论依据:6.5 先要求有效用法能够编译,再比较黑盒的维护成本与诊断距离,并为复杂的内部路径保留策略性白盒断言。
- 原始内容:That being said, white-box testing for macros is a lot of work. Creating the in- and outputs of helper functions, like the ones in this chapter, is cumbersome. (I am excluding functions that have no macro-specific inputs or outputs from this discussion. For that category, see the brief discussion in the previous paragraph.) In a large project, such tests can help you catch bugs early on.