您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > Cactus
Java单元测试工具cactus使用指南
作者:网络转载 发布时间:[ 2013/1/22 15:28:24 ] 推荐标签:

3.实际举例
被测试类: ForwardLauncher

测试类: Test

测试条件1:B=9914,S=123456789,ServerID=AA, BHD0001=1,E=0(程序正常路径,显示选择菜单)

测试条件2:B=9914(程序异常路径,显示发生错误的页面)

Test类内容如下:

package jp.co.abic.wam;

import java.io.IOException;

import javax.servlet.ServletException;

import jp.co.abic.wam.startmenu.ForwardLauncher;

import org.apache.cactus.ServletTestCase;

import org.apache.cactus.WebRequest;

import org.apache.cactus.WebResponse;

/**

* @author sfluo

*

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

* Window - Preferences - Java - Code Style - Code Templates

*/

public class Test extends ServletTestCase {

ForwardLauncher wamServlet=new ForwardLauncher();

public static void main(String[] args) {

junit.textui.TestRunner.run(Test.class);

}

/*

* @see TestCase#setUp()

*/

protected void setUp() throws Exception {

config.setInitParameter("FORWARD_SERVLET","TS2");

wamServlet.init(config);

}

/*

* @see TestCase#tearDown()

*/

protected void tearDown() throws Exception {

super.tearDown();

}

/*

* Class under test for void doGet(HttpServletRequest, HttpServletResponse)

*/

public void beginDoGetHttpServletRequestHttpServletResponseA(WebRequest theRequest){

theRequest.addParameter("B", "9914");

theRequest.addParameter("S", "123456789");

theRequest.addParameter("ServerID", "AA");

theRequest.addParameter("BHD0001", "1");

theRequest.addParameter("E", "0");

}

public final void testDoGetHttpServletRequestHttpServletResponseA() {

try {

wamServlet.doGet(request,response);

} catch (ServletException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//TODO Implement doGet().

}

public final void endDoGetHttpServletRequestHttpServletResponseA(WebResponse theResponse){

System.out.print(theResponse.getText());

}

public void beginDoGetHttpServletRequestHttpServletResponseB(WebRequest theRequest){

theRequest.addParameter("B", "9914");

}

public final void testDoGetHttpServletRequestHttpServletResponseB() {

try {

wamServlet.doGet(request,response);

} catch (ServletException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//TODO Implement doGet().

}

public final void endDoGetHttpServletRequestHttpServletResponseB(WebResponse theResponse){

System.out.print(theResponse.getText());

}

}

详细的api请参照相关的文档,在文件目录下均存在

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd