知识卡片
先看测试为何失败
先以测试描述新增行为,再写能编译的最小骨架。确认测试因行为尚未实现而失败,再写足量代码使其通过,重构后重复运行。在 minigrep 中,骨架返回空列表,清楚暴露缺少命中行。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- I/O 项目:构建命令行程序 Developing the Library’s Functionality with Test-Driven Development · 查看原书依据
We aren’t yet able to run this test and watch it fail because the test doesn’t even compile: the search function doesn’t exist yet! In accordance with TDD principles, we’ll add just enough code to get the test to compile and run by adding a definition of the search function that always returns an empty vector, as shown in Listing 12-16.
参考来源
- 位置:《The Rust Programming Language(第2版)》第12章 I/O 项目:构建命令行程序(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c12.xhtml`,块 0191)
- 结论依据:暂时返回空向量使缺失 API 的编译错误变成可核对的行为断言失败。
- 原始内容:We aren’t yet able to run this test and watch it fail because the test doesn’t even compile: the search function doesn’t exist yet! In accordance with TDD principles, we’ll add just enough code to get the test to compile and run by adding a definition of the search function that always returns an empty vector, as shown in Listing 12-16.