您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > Cactus
用Cactus來測(cè)試J2ee應(yīng)用
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2012/11/29 14:52:41 ] 推薦標(biāo)簽:

try {
h=getHome();
uml=h.create() ;
}
catch (CreateException ex) {
ex.printStackTrace() ;
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

}

public void addUser(HttpServletRequest request, HttpServletResponse response) throws

javax.ejb.EJBException {
String name=request.getParameter("name") ;
String tel=request.getParameter("tel") ;
String address=request.getParameter("address") ;
String email=request.getParameter("email") ;
String pass=request.getParameter("pass") ;
uml.addUser(name,pass,email,address,tel) ;
}
public User findByName(String name) throws javax.ejb.EJBException {
User u = null;

u=uml.findByName(name) ;

return u;
}
public java.util.Iterator findAll() throws javax.ejb.EJBException {
java.util.Collection c=uml.findAll() ;
return c.iterator() ;
}

public void delAll() throws javax.ejb.EJBException {
uml.delAll() ;
}
public void delUser(String name) throws javax.ejb.EJBException {

uml.delByName(name) ;

}
public UserManagerLocalHome getHome() {
UserManagerLocalHome home = null;
try {
javax.naming.InitialContext ctx=new javax.naming.InitialContext ();
home=(UserManagerLocalHome)ctx.lookup("UserManagerLocal") ;
}
catch (NamingException ex) {
ex.printStackTrace() ;
return null;
}
return home;
}

public void destroy() {
}
}

這個(gè)servlet在doGet,doPost沒有實(shí)現(xiàn)任何方法,這個(gè)不影響我們測(cè)試,我們要測(cè)試的只是這些public method. 我們的測(cè)試代碼如下:

package usersystem.test;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import usersystem.servlet.*;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.Hashtable;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.cactus.Cookie;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import javax.ejb.*;
import javax.servlet.*;

import usersystem.*;

public class ManaServletTest extends ServletTestCase{
ManaServlet servlet=new ManaServlet();
public ManaServletTest(String theName) {
super(theName);
}

public void setUp(){

try {
servlet.init() ;
}
catch (ServletException ex) {
ex.printStackTrace() ;
this.fail() ;
}
}
public void tearDown(){

}
public void beginAddUser(WebRequest theRequest)
{
theRequest.addParameter("name", "nameValue");
theRequest.addParameter("pass","passValue") ;
theRequest.addParameter("tel","telValue") ;
theRequest.addParameter("address","addressValue") ;
theRequest.addParameter("email","emailValue");

}

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