您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > Cactus
Java單元測試工具cactus使用指南
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/1/22 15:28:24 ] 推薦標(biāo)簽:

3.實際舉例
被測試類: ForwardLauncher

測試類: Test

測試條件1:B=9914,S=123456789,ServerID=AA, BHD0001=1,E=0(程序正常路徑,顯示選擇菜單)

測試條件2:B=9914(程序異常路徑,顯示發(fā)生錯誤的頁面)

Test類內(nèi)容如下:

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());

}

}

詳細(xì)的api請參照相關(guān)的文檔,在文件目錄下均存在

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd