qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

测试驱动开发笔记(二)—xUnit

  1.  防止改完后引起新错误;再次运行单元测试
  2.. 如果单元测试涉及到可变信息(如当前时间),需要将待测试数据也变为可变,否则无法回归测试
  3. 使用测试驱动开发必须从头开始,严格进行,否则到半中间会很费事的。
  4. 测试驱动开发中,私有方法也要测试,可通过反射实现,如
Summer example = new Summer.newInstance();
Method m = example.getClass().getDeclaredMethod("methodone",new Class[]{String.class});
m.setAccessible(true);Object result = m.invoke(example ,new Object[] {“xxx”});
m.setAccessible(false);
if (result.equals(rightResult)){
  5.重构和修改,一次只带一顶帽子,要掌握自己的pace,不太快也不太慢
  6. 常用断言:相等,真,空,同一对象
  7.  Junit与ant结合,运行全部测试并将运行结果以文件形式输出
  JUnit中测试的组织
import junit.framework.TestCase;
public class CalculateUtilTest extends TestCase
{
public CalculateUtilTest(String name)    //1行
{
super(name);
}
}
1. import junit.framework.*;
2. public class MainTest
3. {
4.     public static Test suite()  //1行
5.     {
6.         TestSuite suite = new TestSuite();  //2行
7.
8.         //添加测试testDivision方法
9.         suite.addTest(new CalculateUtilTest("testDivision"));  //3行
10.
//添加测试类
suite.addTestSuite(CalculateUtil.class);
return suite;
14.     }
15.
16.     public static void main(String[] args)
17.     {
18.         //执行测试
19.         junit.textui.TestRunner.run(suite());   //4行
20.     }
21. }

posted on 2014-01-30 11:57 顺其自然EVO 阅读(207) 评论(0)  编辑  收藏


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


网站导航:
 
<2014年1月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜