同学问:自己设计Q1的测试用例,有典型用法、边界值、对象状态、耗时性能、并发情况、误用情况、反复调用等方面的考虑,这些在目前的示例里没体现,是否有必要考虑,在哪个步骤做合适?
===
我理解,这个问题其实是,How many tests should you write?
这是个好问题。
我之前有个 Kent Beck 的《TDD by example》的读书笔记,可以回答这个问题:
How many tests should you write?
For simple problem of triangle, Kent wrote six tests, Bob Binder wrote 65.
Think about MTBF, if you want the MTBF to be 10 years, you should write more tests.
(下面是原文了)
TDD’s view of testing is pragmatic. In TDD, the tests are a means to have great confidence. If our knowledge of the implementation gives us confidence even without a test, then we will not write that test. Black box testing demonstrates adifferent value system. It’s an appropriate attitude to take in some circumstances, but that is different from TDD.
总结一下就是:“看情况”。测与不测,黑盒白盒,覆盖范围,都看情况。
怎么看情况?
如果很有 confidence,那就不测了。如果有 fear,那可以测测,就像 Kent Beck 说的:“Write tests until fear is transformed into boredom.” 这里 boredom 也可以理解成 Confidence