Alex Rivera | Logout

How do I include test classes and configuration in my war for integration testing using maven?

Asked 2012-12-27T09:56:24.663
8

I currently have a maven web project that I am attempting to write integration tests for. For the structure of the project, I've defined test stubs under src/test/java, whilst the spring bean definitions for these stubs sit under src/test/resources.

What I would like to do, is that when I build my war artifact I'd like all of the test stub classes to be compiled and included in the war along with the spring bean definition files. I've tried to do it with the maven war plugin but the only things I've been able to copy are the resources. Simply put, I'd like to make use of the test class path and include all these classes in my war file.

It seems the useTestClassPath option with the maven jetty plugin would solve my problem but the current project I'm working on is currently using Tomcat 6.0. Is there another maven plugin or a way I can configure the maven war plugin to achieve my objective?

Edit
Report

1 Answer

4

I believe the following configuration for the maven war plugin would do what you want. You copy your test-classes to your WEB-INF/classes folder. You can even filter those resources.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-test-war</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>war</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <warSourceDirectory>${basedir}/src/test/webapp</warSourceDirectory>
        <warName>${project.artifactId}-test</warName>
        <webappDirectory>${basedir}/target/${project.artifactId}-test</webappDirectory>
        <primaryArtifact>false</primaryArtifact>
        <webResources>
            <resource>
                <directory>${basedir}/target/test-classes</directory>
                <targetPath>WEB-INF/classes</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>

See http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

answered 2013-01-10T18:24:18.603

Your Answer