-
什么是好的unit test?
2009-09-02
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://bearwhisper.blogbus.com/logs/45598389.html
根据The Art of Unit Testing With Examples in .NET,好的unit test应该具备如下特点:
- It should be automated and repeatable.
- It should be easy to implement.
- Once it’s written, it should remain for future use.
- Anyone should be able to run it.
- It should run at the push of a button.
- It should run quickly.
如果这还不够,请回答下列问题,足以判断一个测试是否是好的unit test:
- Can I run and get results from a unit test I wrote two weeks or months or years ago?
- Can any member of my team run and get the results from unit tests I wrote two months ago?
- Can I run all the unit tests I’ve written in no more than a few minutes?
- Can I run all the unit tests I’ve written at the push of a button?
- Can I write a basic unit test in no more than a few minutes?
有任何一个问题的回答是“no”,对不起,您的测试不是unit test,而是integration test,书中对于此类测试定义如下:
Integration testing means testing two or more dependent software modules as a group.
因此,unit test的定义如下:
A unit test is an automated piece of code that invokes the method or class being tested and then checks some assumptions about the logical behavior of that method or class. A unit test is almost always written using a unit-testing framework. It can be written easily and runs quickly. It’s fully automated, trustworthy, readable, and maintainable.
随机文章:
多几只眼睛盯着产品——保持项目节奏实践之四 2009-05-19我们马上会变得更快——项目经理应该小心的游戏之十五 2009-05-04我们不能说“不”——项目经理应该小心的游戏之十二 2009-04-282009.4.21 博客阅读笔记——敏捷团队成员与主管之职责 2009-04-21软件项目管理的十条忠告 2009-03-15
收藏到:Del.icio.us







