gpt4 book ai didi

java - Maven 在集成测试阶段运行 jetty

转载 作者:搜寻专家 更新时间:2023-11-01 02:08:24 25 4
gpt4 key购买 nike

我使用 failsafe 插件。

因此,当我输入 mvn failsafe:integration-test 时,它会启动我的集成测试(这很棒)。

但我希望我的jetty serverpre-integration 阶段启动。我该怎么办?

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

有两个插件:

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

最佳答案

这是 jetty 和 maven-failsafe-plugin 使用手册:

Maven Failsafe Plugin – Usage

它提供了一个示例配置,用于将 Jetty 集成到集成测试生命周期中。

Jetty 在 pre-integration-test 阶段启动,在 vpost-integration-test 阶段停止。

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

但是,它也特别推荐你使用verify阶段:

The recommendation is that you do not directly invoke thepre-integration-test, integration-test or post-integration-test phasesbut that instead you run integration tests by specifying the verifyphase. [...]

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

关于java - Maven 在集成测试阶段运行 jetty ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25127982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com