Welcome

首页 / 软件开发 / 数据结构与算法 / 实战从需求文档到设计文档的书写规范(四)

实战从需求文档到设计文档的书写规范(四)2011-01-231.2 junit单元测试

大部分集成工具都集成了junit单元测试插件,并有向导帮助写单元测试。Junit发行包的文档很详细地介绍了Junit的设计概念和所使用的设计模式。在这里我简单地说明如何写测试用例、在ant配置文件中调用测试用例和产生测试报告的方法。

写测试用例

下面是在eclipse junit向导对MyCode类编写的测试用例TestMyCode文件基础上写的代码:

import junit.framework.TestCase;

/*

* Created on 2003-4-30

*

* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

/**

* @author gongys

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class TestMyCode extends TestCase {

MyCode myFixture=null;

/**

* Constructor for TestTest.

* @param arg0

*/

public TestTest(String arg0) {

super(arg0);

}

/*

* @see TestCase#setUp()

*/

protected void setUp() throws Exception {

super.setUp();

myFixture = new MyCode();

System.out.println("setup");

}

/*

* @see TestCase#tearDown()

*/