知识卡片
单元测试贴近实现
把单元测试放在实现的同一源文件内,可局部验证单元并快速定位失败。测试模块用 #[cfg(test)] 条件编译,使普通构建省下这些代码。子模块能使用祖先模块的私有项,use super::* 可将父模块的项带入作用域。
相关卡片 [[集成测试按使用者验证]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 编写自动化测试 Test Organization · 查看原书依据
Note that the internal_adder function is not marked as pub. Tests are just Rust code, and the tests module is just another module. As we discussed in “Paths for Referring to an Item in the Module Tree” on page 125, items in child modules can use the items in their ancestor modules.
参考来源
- 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0201)
- 结论依据:私有 `internal_adder` 可由子模块直接调用,来自通常的模块可见性规则。
- 原始内容:Note that the internal_adder function is not marked as pub. Tests are just Rust code, and the tests module is just another module. As we discussed in “Paths for Referring to an Item in the Module Tree” on page 125, items in child modules can use the items in their ancestor modules.