我希望 Jetty 在集成测试之前启动,以便我可以针对我的 Web 应用程序运行 Selenium 集成测试。但是,当我运行 mvn verify 时,Jetty 未启动,Selenium 测试自然会失败。任何想法有什么问题吗?
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.M1</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
最佳答案
您使用了运行单元测试的maven-surefire-plugin
。但就您而言,您想要运行集成测试。
您必须使用maven-fail-safeplugin为了运行集成测试。这个插件有两个目标:integration-test
& verify
,集成在maven生命周期中:
预集成测试
集成测试
集成后测试
验证
所以在你的情况下使用类似的东西:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<configuration>
...
</configuration>
</executions>
</plugin>
希望有帮助。
关于java - 无法在预集成测试阶段启动 Jetty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984032/