I use failsafe
plugin.
So when I type mvn failsafe:integration-test
it stars my integration tests (which is great).
But I want my jetty server
starts on pre-integration
stage then. What should I do?
(I don't want launch mvn verify
since it involves whole cycle running, but mvn failsafe:integration-test
- it seems it's supposed to work that way)
There are two plugins:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId> <!-- for starting jetty for integration tests -->
<version>2.16</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>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<!--<jettyConfig>${project.basedir}/src/main/resources/config/jetty9.xml</jettyConfig>-->
<stopKey>STOP</stopKey>
<stopPort>9999</stopPort>
<stopWait>5</stopWait>
<scanIntervalSeconds>5</scanIntervalSeconds>
<scanTargets>
<scanTarget>${project.basedir}/src/main</scanTarget>
<scanTarget>${project.basedir}/src/test</scanTarget>
</scanTargets>
<contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
<webAppConfig>
<contextPath>/${project.artifactId}-${project.version}</contextPath>
</webAppConfig>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase> <!-- In the pre-integration-test phase the Jetty server will be started -->
<goals>
<goal>run-exploded</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase> <!-- in the "post-integration-phase" it will be stopped -->
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
This is the jetty and maven-failsafe-plugin usage manual:
Maven Failsafe Plugin – Usage
It provides a sample configuration for integrating Jetty into the integration test life-cycle.
Jetty is started during the
pre-integration-test
phase and stopped during the vpost-integration-test
phase.However, it also specifically recommends that you use the
verify
phase:I prefer starting jetty on the fly programmatically inside the test cases. Main reasons for this is: