知识卡片
集成用例共用辅助模块
多个集成测试目标共用初始化时,可将实现放在 tests/common/mod.rs,在各测试文件声明 mod common;。同一辅助函数若放在 tests/common.rs,Cargo 会把该文件也当作独立集成测试目标,报告多出一个空用例组。
相关卡片 [[集成测试按使用者验证]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 编写自动化测试 Submodules in Integration Tests · 查看原书依据
This is the older naming convention that Rust also understands that we mentioned in “Alternate File Paths” on page 139. Naming the file this way tells Rust not to treat the common module as an integration test file. When we move the setup function code into tests/common/mod.rs and delete the tests/common.rs file, the section in the test output will no longer appear.
参考来源
- 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0231)
- 结论依据:原文比较两种落盘布局,说明子目录文件不被编译成独立测试 crate。
- 原始内容:This is the older naming convention that Rust also understands that we mentioned in “Alternate File Paths” on page 139. Naming the file this way tells Rust not to treat the common module as an integration test file. When we move the setup function code into tests/common/mod.rs and delete the tests/common.rs file, the section in the test output will no longer appear.