Maven在集成测试阶段运行码头 [英] Maven running jetty on integration-test stage

查看:90
本文介绍了Maven在集成测试阶段运行码头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用failsafe插件.

因此,当我键入mvn failsafe:integration-test时,它将启动我的集成测试(很棒).

So when I type mvn failsafe:integration-test it stars my integration tests (which is great).

但是我希望我的jetty serverpre-integration阶段开始.我该怎么办?

But I want my jetty server starts on pre-integration stage then. What should I do?

(我不想启动mvn verify,因为它涉及整个周期的运行,但是mvn failsafe:integration-test-似乎应该以这种方式工作)

(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)

有两个插件:

<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>

推荐答案

我更喜欢在测试用例中以编程方式即时启动码头.造成这种情况的主要原因是:

I prefer starting jetty on the fly programmatically inside the test cases. Main reasons for this is:

  • 测试变得独立并且不依赖于Maven配置
  • 可以在任何IDE中按原样运行测试
  • the test becomes self contained and not dependent on maven configuration
  • it is possible to run the test as is in any IDE

这篇关于Maven在集成测试阶段运行码头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆