← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 743.d.2.b.5.a.2.a.3 · 生成模型:GPT-6

黑盒验证宏的调用行为

理解等级:中级

黑盒测试用宏使用者能写出的代码验证接口和结果。书中先对空结构体执行 let _: ExampleStructNoFields = ExampleStructNoFields::builder().build();,将生成的入口、构造方法和返回类型交给编译器检查。再加入实际字段,使用 setter 传值并断言成品中的值,区分“代码能编译”和“值被正确传递”。只要相应契约维持,内部令牌次序或存储方式的变化通常无需改测试。

相关卡片 [[白盒断言宏展开输出]]、[[编译失败测试核对诊断]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Testing a builder macro 从调用端验证可编译 · 查看原书依据

      As we mentioned earlier, black-box tests take an outsider’s view. They only want to know whether the code produces the required result, without knowing how it achieves this. This is often a good idea since the value of code is in what it can produce rather than how. Do we really care that values are temporarily stored somewhere when we build our struct? Is it important to verify that this happens?

    参考来源

    - 位置:《Write Powerful Rust Macros》第06章《Testing a builder macro》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-6.xhtml#p50) - 结论依据:6.4.1 用空结构体和显式类型验证生成接口可以编译,6.4.2 断言通过 setter 交给构建器的值实际出现在完成的结构体中。 - 原始内容:As we mentioned earlier, black-box tests take an outsider’s view. They only want to know whether the code produces the required result, without knowing how it achieves this. This is often a good idea since the value of code is in what it can produce rather than how. Do we really care that values are temporarily stored somewhere when we build our struct? Is it important to verify that this happens?