java 为什么“mvn verify”不运行我的集成测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33923601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why doesn't "mvn verify" run my integration tests?
提问by Daniel Kaplan
I have a multi-module project and I have failsafe defined in the root pom like this:
我有一个多模块项目,并且在根 pom 中定义了故障保护,如下所示:
<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>
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.
在我的其他 poms 中的其他任何地方都没有定义故障安全。如果我运行mvn verify
,它会跳过集成测试(它运行单元测试)。但是如果我运行mvn test-compile failsafe:integration-test
,它会运行集成测试。
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
?
我假设故障安全应该在这两种情况下运行。那么为什么当我输入时它不运行mvn verify
?
UPDATE: Just noticed that this was wrapped around these tags:
更新:刚刚注意到这是围绕这些标签:
<build>
<pluginManagement> <!-- oops -->
<plugins>
<plugin>
I feel like this explains the cause, but I'm not sure why unittests still run like you'd expect with mvn verify
and mvn test
. Why does surefire work differently from failsafe in this respect?
我觉得这解释了原因,但我不确定为什么单元测试仍然像你期望的那样运行mvn verify
和mvn test
。在这方面,为什么surefire 与failsafe 的工作方式不同?
回答by JJF
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").
您需要将故障安全的集成测试目标绑定到 Mavenintegration-test
和verify
阶段。默认情况下,故障安全插件不包含在vanilla
Maven 项目中。你需要添加它。因此,即使存在integration-test
生命周期,默认情况下也不包含它(好吧,至少不运行maven-failsafe-plugin
)。您将它添加到integration-test
和verify
阶段(它需要两者,它只会在该verify
阶段构建失败[如果前面的集成测试失败],因此post-integration
生命周期阶段仍然有机会运行和清理资源,因此得名“故障安全”)。
<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>
回答by Cristi B.
I encountered a similar issue when running mvn verify as the integration tests were not executed, but only the unit tests. It worked after marking skipTeststo false:
我在运行 mvn verify 时遇到了类似的问题,因为没有执行集成测试,而只执行了单元测试。它在将skipTests标记为false后起作用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>