这是我的项目目录结构:
TOPS-WEB
|___
| Java Resources
|___
WebContent
|____
WEB-INF
|____
| web.xml
|____
| lib
| |__
| strutstest-2.1.4.jar
|____
struts
|__
struts-info-config.xml
当我运行测试时,出现以下错误。此错误由 testInfo() 方法中的 setServletConfig(...) 行引发。
ERROR [main] org.apache.struts.action.ActionServlet initServlet - The /WEB-INF/web.xml was not found.
ERROR [main] org.apache.struts.action.ActionServlet init - Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
我的测试班
public class MyTest extends MockStrutsTestCase{
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public MyTest(String testName){
super(testName);
}
public void testInfo(){
setContextDirectory(new File("TOPS-WEB/WebContent"));
setConfigFile(this.getSession().getServletContext().getRealPath("/WEB-INF/struts/struts-info-config.xml"));
*setServletConfigFile(this.getSession().getServletContext().getRealPath("/WEB-INF/web.xml"));*
setRequestPathInfo("/infoPopup");
actionPerform();
}
}
我看到一些地方提到你必须使用 maven,但我不是。我只需右键单击测试类并将其作为 junit 运行。这可能是原因吗?