3.實(shí)際舉例
被測試類: 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)的文檔,在文件目錄下均存在