MavenソリューションとSurefireソリューションの2つのオプションがあります。最も結合の少ないソリューションは、pre-integration-test
andpost-integration-test
フェーズでプラグインを実行することです。ビルドライフサイクルの概要-ライフサイクルリファレンスを参照してください。私はグリズリーに精通していませんが、ここに桟橋を使用した例があります:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/xxx</contextPath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
のフェーズはであることに注意start
しpre-integration-test
てstop
くださいpost-integration-test
。grizzly mavenプラグインがあるかどうかはわかりませんが、代わりにmaven-antrun-pluginを使用できます。
2番目のオプションは、JUnitRunListenerを使用することです。RunListener
テストの開始、終了、テストの失敗、テストの成功などのテストイベントをリッスンします。
public class RunListener {
public void testRunStarted(Description description) throws Exception {}
public void testRunFinished(Result result) throws Exception {}
public void testStarted(Description description) throws Exception {}
public void testFinished(Description description) throws Exception {}
public void testFailure(Failure failure) throws Exception {}
public void testAssumptionFailure(Failure failure) {}
public void testIgnored(Description description) throws Exception {}
}
したがって、RunStartedとRunFinishedをリッスンできます。これらはあなたが望むサービスを開始/停止します。次に、surefireで、次を使用してカスタムリスナーを指定できます。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
</property>
</properties>
</configuration>
</plugin>
これは、Maven Surefireプラグイン、JUnitの使用、カスタムリスナーとレポーターの使用からのものです。