开发者

How do I make a WAR archive produced with maven-assembly-plugin available for other projects' unit tests?

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 p开发者_JAVA百科roject 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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜