İki seçenek vardır, bir maven çözümü ve kesin bir çözüm. En az birleşik çözüm, bir eklentiyi pre-integration-test
ve post-integration-test
fazında yürütmektir. Bakınız Introduction to the Build Lifecycle - Lifecycle Reference. Ben grizzly aşina değilim, ama burada bir örnek kullanarak dalgakıran: start
için faz pre-integration-test
ve stop
post-integration-test
olduğunu olduğunu
<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>
Not. Bir grizzly maven eklentisi olup olmadığından emin değilim, ancak bunun yerine maven-antrun-plugin'u kullanabilirsiniz.
İkinci seçenek bir JUnit RunListener kullanmaktır. RunListener
Yani RunStarted ve RunFinished dinlemek olabilir vb
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 {}
}
Test başlangıcında test sonunda test yetmezliği, deney başarı olarak olayları sınamak dinler. Bunlar istediğiniz hizmetleri başlatacak/durduracaktır. Sonra güzelliğinde de, kullandığınız özel bir dinleyici belirtebilirsiniz:
<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>
Bu jUnit değilse kullandığınız bir Maven Surefire Plugin, Using JUnit, Using custom listeners and reporters
geliyor? – TheWhiteRabbit
POJO veya TestNG testlerini kullanıyorsanız, @BeforeClass – TheWhiteRabbit
@TechExchange'i kullanabilirsiniz. Güncellenmiş soru maven surefire – hertzsprung