2006-03-26 校对记要
校对文件: roman.xml
本章目录
Chapter 15. Refactoring 重构
15.1. Handling bugs
bugs 处理 处理bug
15.2. Handling changing requirements 应对
要求需求变化
15.3. Refactoring
重组 重构
- 15.4. Postscript 后记
- 15.5. Summary 小结
第15章第1节
第一段
- Despite your best efforts to write comprehensive unit tests, bugs happen. What do I mean by “bug”? A bug is a test case you haven't written yet.
尽管你很努力
的地编写全面的单元测试,但是 bug 还是会出现。 我所说的 “bug” 是什么呢? Bug 是你还没有编写的一个
独立测试测试用例。
Example 15.1. The bug
- Example 15.1. The bug
例 15.1.
关于一个 Bug
Example 15.1.说明1
Remember in the previous section when you kept seeing that an empty string would match the regular expression you were using to check for valid Roman numerals? Well, it turns out that this is still true for the final version of the regular expression. And that's a bug; you want an empty string to raise an InvalidRomanNumeralError exception just like any other sequence of characters that don't represent a valid Roman numeral.
在前面的 章节中 你
看到你有注意到一个空字符串会匹配
用以那个检查罗马数字有效性的正则表达式认为空字符串有效了吗? 对于最终版本中的正则表达式这一点仍然没有改变。这就是一个 Bug ,你希望对于空字符串能够像对待其他无效的罗马数字表示一样引发 InvalidRomanNumeralError 异常。
下一段
- After reproducing the bug, and before fixing it, you should write a test case that fails, thus illustrating the bug.
在
再现 重现这个 Bug 和
去除修复它之前你应该编写一个
失败独立测试会失败的测试用例来
描述这个 Bug说明它。
Example 15.2.说明1
Pretty simple stuff here. Call fromRoman with an empty string and make sure it raises an InvalidRomanNumeralError exception. The hard part was finding the bug; now that you know about it, testing for it is the easy part.
这里很简单。以空字符串调用 fromRoman 并确保
它会引发一个 InvalidRomanNumeralError 异常。 难点在于找出 Bug,<!> 现在你知道了它既然你已经知道它了,测试它就很
简单容易了。