gr8vyguy@Blogjava

Automated Unit Test

The TDD cycle looks like this:

  1. Write a test for the next bit of functionality you have in mind. The test should succeed only when the functionality has been implemented correctly.

  2. Make the test compile by creating stubs for all the missing classes and methods referenced by the test.

  3. Run the test. It should fail.

  4. Implement just enough functionality to get the test to succeed.

  5. Clean up the implementation as much as possible, typically by removing duplication.

这里最难的是第一点的第二句,"只有正确的程序才能通过测试"。 这几乎是不可能的,即使可能,所耗的时间也不亚于编写代码的时间. 第四点的提法更有问题,程序员在编程实现功能的时候应该把注意力集中在所实现的代码,而不是测试上。

The Test/Code Cycle in XP

  • Write one test.
  • Compile the test. It should fail, as you haven't implemented anything yet.
  • Implement just enough to compile. (Refactor first if necessary.)
  • Run the test and see it fail.
  • Implement just enough to make the test pass.
  • Run the test and see it pass.
  • Refactor for clarity and "once and only once".
  • Repeat from the top.


 

posted on 2007-04-21 23:33 gr8vyguy 阅读(457) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航:
 
<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

导航

统计

公告

  • 转载请注明出处.
  • msn: gr8vyguy at live.com
  • 常用链接

    留言簿(9)

    随笔分类(68)

    随笔档案(80)

    文章分类(1)

    My Open Source Projects

    搜索

    积分与排名

    最新评论