随笔 - 3, 文章 - 152, 评论 - 17, 引用 - 0
数据加载中……

Test-Driven Development

 

Test-Driven Development

http://www.xprogramming.com/xpmag/whatisxp.htm#test

Extreme Programming is obsessed with feedback, and in software development, good feedback requires good testing. Top XP teams practice "test-driven development", working in very short cycles of adding a test, then making it work. Almost effortlessly, teams produce code with nearly 100 percent test coverage, which is a great step forward in most shops. (If your programmers are already doing even more sophisticated testing, more power to you. Keep it up, it can only help!)

It isn't enough to write tests: you have to run them. Here, too, Extreme Programming is extreme. These "programmer tests", or "unit tests" are all collected together, and every time any programmer releases any code to the repository (and pairs typically release twice a day or more), every single one of the programmer tests must run correctly. One hundred percent, all the time! This means that programmers get immediate feedback on how they're doing. Additionally, these tests provide invaluable support as the software design is improved.

在上面的图中,列出的的是XP的12个团队实践。Test-Driven Development是其中之一。
Kent Beck 的著作TDD(Test Driven Development) 中详细讲述了测试驱动开发。
在XP中测试是一种设计,不是简单的为了测试你的功能是否实现。测试先行一个目的
是可以在代码编写之前,保证测试已经写好;其实这些测试的另一个目的就是设计接口,
保证接口在以后的修改过程中能够满足测试(设计)。当你有意或无意修改接口的时候,你必须同时
修改测试 要改动接口的时候,也应该是先修改测试,再修改代码。而不是修改代码等着报错再修改
测试(设计)。(测试必须100%通过才能进行下一个功能),这样测试也是在提醒你,接口已经改变。
实际上,设计已经改变。当你修改单元测试的时候,可能就会遭到抱怨。为什么?你修改了设计
,别人的代码是依赖你修改前的测试(设计),那么新的测试(设计)中的变动可能要影响到
别人已有的代码。
 
当你使用TDD的时候一定要说明是测试驱动开发还是测试驱动设计。这两者是有区别的。测试驱动
开发,是通过测试定义所要开发的功能的接口,然后实现功能的开发过程。对于测试驱动设计,在XP中似乎
已经消失了,而是被测试驱动开发所取代。另外在XP中有用于描述设计的,SimpleDesign ,Design Improvement.
在XP中测试是一种设计,设计之后才有开发,这也就是为什么要测试先行了。
在XP中测试是一种文档,用于描述设计。

posted on 2005-07-25 12:22 阅读(154) 评论(0)  编辑  收藏 所属分类: Test-Driven Development


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


网站导航: