I'm using Maven 2 to build a Java - Sturts 1.2 - Spring 1.2 project. I'm trying to incorporate the StrutsTestCase extension of JUnit to allow testing of action classes.
When I try to build, I get the following error:
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)
In researching this, I've learned the following:
- If your
web.xml
file is in a non-standard location, thensetServletConfigFile()
can be used to indicate toStrutsTestCase
where the file is. - When building with Maven, it may be necessary to indicate what resources should be included in the
pom.xml
.
I'm trying to implement this, here is my current progress:
Test class:
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 */ }
I have included the following testResources
in the build
tag in the pom.xml
.
<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>
Here is the structure of the project:
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
Of course, I've tried a variety of variations of the paths in pom.xml
and in setServletConfigFile
. I've also tried using setContextDirectory
, with no different result.