メイヴァンソリューションと確実なソリューションの2つのオプションがあります。最も結合されていない解決策は、pre-integration-test
とpost-integration-test
フェーズでプラグインを実行することです。 Introduction to the Build Lifecycle - Lifecycle Referenceを参照してください。私はグリズリーに慣れていないんだけど、ここでは例として使用して桟橋です:start
ための位相はpre-integration-test
とstop
がpost-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>
注意。グリズリーメイヴンプラグインがあるかどうかはわかりませんが、代わりにmaven-antrun-pluginを使用できます。
2番目のオプションは、JUnit RunListenerを使用することです。 RunListener
だから、あなたがRunStartedとRunFinishedのために聞くことができなど
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 {}
}
試験開始、テスト終了、テストの失敗、テストの成功などのイベントを、テストするためにリッスンします。これらは、あなたが望むサービスを開始/停止します。
<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>
をJUnitのない場合、これはあなたがいずれかを使用しているMaven Surefire Plugin, Using JUnit, Using custom listeners and reporters
からである。次に、確実な中で、あなたが使用して、独自のリスナーを指定することができますか? – TheWhiteRabbit
POJOまたはTestNGテストを使用している場合は、@BeforeClassを使用することができます – TheWhiteRabbit
@TechExchange Maven surefireを使用していることを明確にするための質問を更新しました – hertzsprung