Ci sono due opzioni, una soluzione esperta e una soluzione infallibile. La soluzione meno accoppiata è quella di eseguire un plug-in nella fase pre-integration-test
e post-integration-test
. Vedi Introduction to the Build Lifecycle - Lifecycle Reference. Non ho familiarità con grizzly, ma qui è un esempio con pontile:
<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>
nota che la fase di start
è pre-integration-test
e stop
è post-integration-test
. Non sono sicuro se sia disponibile un plug-in per i grigi, ma potresti usare lo maven-antrun-plugin.
La seconda opzione è utilizzare JUnit RunListener. RunListener
ascolta per testare gli eventi, come l'avvio di test, fine prova, fallimento del test, il successo di prova ecc
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 {}
}
Così si potrebbe ascoltare per RunStarted e RunFinished. Questi avviare/interrompere i servizi che si desidera. Poi, in infallibile, è possibile specificare un listener personalizzato, utilizzando:
<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>
Questo è da Maven Surefire Plugin, Using JUnit, Using custom listeners and reporters
fonte
2013-02-08 12:33:29
quale stai usando se non JUnit? – TheWhiteRabbit
se stai usando i test POJO o TestNG puoi usare @BeforeClass – TheWhiteRabbit
@TechExchange Aggiornamento per chiarire che sto usando maven surefire – hertzsprung