Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven running jetty on integration-test stage

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>
like image 639
ses Avatar asked Aug 04 '14 21:08

ses


Video Answer


1 Answers

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.

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.16</version>
    <executions>
      <execution>
        <id>start-jetty</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <scanIntervalSeconds>0</scanIntervalSeconds>
          <daemon>true</daemon>
        </configuration>
      </execution>
      <execution>
        <id>stop-jetty</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

However, it also specifically recommends that you use the verify phase:

The recommendation is that you do not directly invoke the pre-integration-test, integration-test or post-integration-test phases but that instead you run integration tests by specifying the verify phase. [...]

This allows you to set-up your integration test environment during the pre-integration-test phase, run your integration tests during the integration-test phase, cleanly tear-down your integration test environment during the post-integration-test phase before finally checking the integration test results and failing the build if necessary.

like image 73
metacubed Avatar answered Oct 31 '22 13:10

metacubed