首先,您應該將集成測試放到單個模塊中讓我們假設您使用模塊A,而不是您應該在同一模塊上運行集成測試階段,而不是在不同的模塊中。
您可以使用cargo-plugin在預集成測試階段爲應用服務器啓動一個啓動程序,通過maven-failsafe插件運行集成測試,並在集成後階段關閉應用服務器,通過貨物插件進行測試。 下面是配置cargo plugin啓動/停止Tomcat服務器的摘要,但貨物還支持JBoss的,Glassfish的等
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.5</version>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://www.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<installDir>${installDir}</installDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>9080</cargo.servlet.port>
<cargo.jvmargs>-DHUDSON_HOME=${project.build.directory}/hudson-storage</cargo.jvmargs>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>hudson-war</artifactId>
<type>war</type>
<pingURL>http://localhost:9080/hudson</pingURL>
<pingTimeout>60000</pingTimeout>
<properties>
<context>hudson</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
下面的代碼片段爲您提供瞭如何使用maven-surefire插件和編譯器的印象插件:在這種情況下,重要的是名稱的集成測試(如XYZ * IT.jav)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
你不需要Exec插件等或shell腳本在運行Maven的集成測試。
的「最佳做法」是對模塊本身的模塊測試。 – 2011-03-08 17:02:44