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请参照相关的文档,在文件目录下均存在