views:

16

answers:

1

My problem consists of two maven projects, a server project A and a client project B. A uses maven-assembly-plugin to produce several variants of A, where one variant is a WAR archive. The problem I am facing relates to the test-driven development of B; how can I make the WAR archive produced in project A accessible/addressable from unit tests in project B? My idea is to construct test cases in project B where the WAR archive is deployed in an embedded Jetty server through the WebApppContext's setWar(String path) function.

+1  A: 

You can declare an artifact from the other submodule as a test dependency, e.g.:

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>ModuleA</artifactId>
        <version>${project.version}</version>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>

</dependencies>

In this way, you can surely use jars from the other module. I am not sure if it works for a WAR file though - but it may be worth a try.

Note that tests run against a WAR deployed in an embedded web container would hardly count as unit tests, rather integration tests. The approach that works in out project is:

  1. build the web app (in our case an EAR) and deploy it (we are using the JBoss Maven plugin, but it could be e.g. Cargo or others in your case)
  2. run a separate build (with a specific timeout to allow the server to start up) which executes the integration tests against the deployed web app
Péter Török
Thank you for your answer, I managed to get it working by using the <type>-tag in the dependency declaration and adjusting the maven-dependency-plugin a bit.
indifferen7