【发布时间】:2011-08-15 20:43:07
【问题描述】:
我正在使用 Maven 2 构建 Java - Sturts 1.2 - Spring 1.2 项目。我正在尝试合并 JUnit 的 StrutsTestCase 扩展以允许测试动作类。
当我尝试构建时,我收到以下错误:
junit.framework.AssertionFailedError: The /WEB-INF/web.xml was not found.
at servletunit.struts.MockStrutsTestCase.getActionServlet(MockStrutsTestCase.java:344)
at servletunit.struts.MockStrutsTestCase.tearDown(MockStrutsTestCase.java:130)
通过研究,我了解到以下内容:
- 如果您的
web.xml文件位于非标准位置,则setServletConfigFile()可用于向StrutsTestCase指示文件所在的位置。 - 使用 Maven 构建时,可能需要在
pom.xml中指明应包含哪些资源。
我正在尝试实现这一点,这是我目前的进展:
测试类:
import servletunit.struts.MockStrutsTestCase;
public class FooActionTest extends MockStrutsTestCase {
public void setUp() throws Exception {
super.setUp();
setServletConfigFile("webapp/WEB-INF/web.xml");
}
public void testTest() throws Exception { /* stub, no content */ }
我在pom.xml 的build 标记中包含了以下testResources。
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>*.*</include>
</includes>
</testResource>
<testResource>
<directory>webapp/WEB-INF</directory>
<includes>
<include>*.xml</include>
</includes>
</testResource>
</testResources>
这是项目的结构:
myproject
│---src
│ |---main
| | |---java
| |
| |---test
| |---Java
|
|---target
| |---classes
| |
| |---MYPROJECT
| |---META-INF
| |---WEB-INF
| |---struts.config.xml
| |---web.xml
|
|---webapp
| |---META-INF
| |---WEB-INF
| |---struts.config.xml
| |---web.xml
|---pom.xml
当然,我在pom.xml 和setServletConfigFile 中尝试了各种路径的变体。我也试过使用setContextDirectory,没有不同的结果。
【问题讨论】:
-
按照 Maven 约定将
webapp移动到src/main/webapp时会发生什么? -
好的,我试过了,但没有帮助。谢谢你的想法。
标签: java unit-testing maven junit struts-1