|
cactusstrutstestcase测试:一直提示我找不到config
最近参加一个项目,我做的是测试的部分,由于项目很多都是用struts框架做的,因此,我也必须学习一种新的测试工具:struttestcase。但是,我在尝试cactusstrutstestcase得时候却遇到了问题:java.lang.NoSuchFieldError: config
at servletunit.struts.CactusStrutsTestCase.setUp(CactusStrutsTestCase.java:105)
at test.TestLogin.setUp(TestLogin.java:8)
at junit.framework.TestCase.runBare(TestCase.java:128)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:225)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:225)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:225)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
我的测试用例是这样得:
LoginAction.java
package com.yourcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.LoginForm;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
String user=loginForm.getUserName();
String pwd=loginForm.getPassword();
if(user.equals("test")&&pwd.equals("1234"))
{
return (mapping.findForward("success"));
}
return (mapping.findForward("fail"));
}
}
LoginForm.java:
package com.yourcompany.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public void setUserName(String userName) {
this.userName = userName;
}
}
测试的代码如下:
package test;
import servletunit.struts.CactusStrutsTestCase;
public class TestLogin extends CactusStrutsTestCase {
public void setUp() throws Exception {
super.setUp();
this.setConfigFile("D:/Workspace/cactus/WebRoot/WEB-INF/web.xml","D:/Workspace/cactus/WebRoot/WEB-INF/struts-config.xml");
}
public void testsuccesslogin()throws Exception{
setRequestPathInfo("/login");
addRequestParameter("userName","test");
addRequestParameter("password","1234");
actionPerform();
verifyNoActionErrors();
verifyForward("success");
}
}
遇到这个问题,自己百度和谷歌了好久,也没有找到解决的方法,希望论坛的高手能帮帮忙。 |
|