您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > Cactus
用Cactus来测试J2ee应用
作者:网络转载 发布时间:[ 2012/11/29 14:52:41 ] 推荐标签:

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() {
}
}

这个servlet在doGet,doPost没有实现任何方法,这个不影响我们测试,我们要测试的只是这些public method. 我们的测试代码如下:

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

}

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