P86有两件事可以帮你确保测试代码是正确的:在修改bug的同时改进测试通过引入bug来验证测试(P96 英文版位置) 修改bug ,而 make sure that this bug never escapes again.All it takes is four steps:1. Indentify the bug[book翻译为:验明bug,但自己feel识别和定位这个bug在coding中的位置才是这里表达的内容]2.Write a test that fails, to prove the bug exists.[这里应该是用unittest code编写,重现这个bug。用这个add new testcase,证明原coding中1被定位的bug确实存在]3.Fix the code such that the test now pass4.Verify that all tests still pass(ie. you didn't break anything else as a result of the fix)(P97)Could this same kind of problem happen anywhere else ?Then it doesn't matter whether you're fixing a bug in an old feature or new feature;either way ,apply what you're just learn to the whole project .Encode your new found knowledge in all the unittest that are approprate,and you're done more than just fix one bug.You're caught a while class of bugs.[popexizhi:这个重现过程是定位,unittest testcase add 重现问题,修改原code,testcase通过,all testcase 验证确认修改未引入新的bug。 思考是否有同类问题是否都要求修改。这个级别的修改后验证没有引入新问题的过程正是那张安全网,也是unittest最漂亮的地方:).多说一句这里的add new testcase的是一个很好的确认问题code定位的方式,不知功能测试中的精确类比是否有:)]P87 Spring the Trap(自设圈套)如果你不确定测试是否正确,最简单的事情就是"Spring the Trap",让产品代码产生你想要的bug,然后测试是否如预测一遍失败。(If you're not sure that a test is written correctly, the easiest thing to do is to "spring the trap";casue the prodution code to exhibit the very bug you're trying to detect, and verify that the test fails as expected.)
html tool
2013年7月25日星期四
《单元测试之道Java版》 note(四)
订阅:
博文评论 (Atom)
没有评论:
发表评论