为什么不"MVN验证"?运行我的集成测试? [英] Why doesn't "mvn verify" run my integration tests?
问题描述
我有一个多模块项目,并且在root pom中定义了故障安全,如下所示:
I have a multi-module project and I have failsafe defined in the root pom like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*JourneyTest.java</include>
<include>**/*CucumberFeatureTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*JourneyTest.java</exclude>
<exclude>**/*CucumberFeatureTest.java</exclude>
</excludes>
</configuration>
</plugin>
在其他pom中的其他任何地方都未定义故障安全.如果运行mvn verify
,它将跳过集成测试(运行单元测试).但是,如果我运行mvn test-compile failsafe:integration-test
,它将运行集成测试.
Failsafe is not defined anywhere else in my other poms. If I run mvn verify
, it skips integration tests (it runs unit tests). But if I run mvn test-compile failsafe:integration-test
, it runs integration tests.
我假设故障保险应该在这两种情况下都可以运行.那么为什么当我键入mvn verify
时它不运行?
I'm under the assumption that failsafe is supposed to run in both of these situations. So why doesn't it run when I type mvn verify
?
更新:刚刚注意到,这些标记被包裹在这些标记中:
UPDATE: Just noticed that this was wrapped around these tags:
<build>
<pluginManagement> <!-- oops -->
<plugins>
<plugin>
我觉得这可以解释原因,但是我不确定为什么 unit 测试仍然可以像您期望的那样使用mvn verify
和mvn test
运行.为什么surefire在这方面与故障安全有所不同?
I feel like this explains the cause, but I'm not sure why unit tests still run like you'd expect with mvn verify
and mvn test
. Why does surefire work differently from failsafe in this respect?
推荐答案
您需要将故障保险的集成测试目标绑定到maven的integration-test
和verify
阶段.默认情况下,故障保护插件不包含在vanilla
maven项目中.您需要添加它.因此,即使存在integration-test
生命周期,默认情况下也不包含它(嗯,至少不运行maven-failsafe-plugin
).您将其添加到integration-test
和verify
阶段(需要同时使用,它将仅在verify
阶段失败(如果先前的集成测试失败),因此post-integration
生命周期阶段仍然具有运行和清理资源的机会,因此命名为故障保护".
You need to bind failsafe's integration test goal to maven's integration-test
and verify
phases. By default the failsafe-plugin isn't included in a vanilla
maven project. You need to add it. So even though there is an integration-test
lifecycle, by default it is not included (well, at least doesn't run the maven-failsafe-plugin
). You add it to the integration-test
and verify
phases (it needs both, it will fail the build at the verify
phase only [if the preceding integration-tests failed], so that the post-integration
lifecycle phase still has a chance to run and cleanup resources, hence the name "fail safe").
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*JourneyTest.java</include>
<include>**/*CucumberFeatureTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于为什么不"MVN验证"?运行我的集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!