英文:
How to ignore the specific failed unit test result in Maven build?
问题
我有一些位于Integration.java
下的单元测试。我希望Maven忽略这个类的测试结果,因为它们很少失败(由于外部服务器维护)。但我不想让它们在运行时被忽略,因为我需要它们来进行代码覆盖率测试。
我尝试了以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>IntegrationTest.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
这似乎有效,因为它会忽略失败的测试。但上述配置的问题是,它也会忽略其他类中的失败测试。
我希望所有位于Integration.java
下的测试都能执行,但不应影响构建的成功或失败。但是,如果除了Integration.java
之外的任何其他测试类中的测试用例失败,构建应该失败。
英文:
I have some unit tests under Integration.java
. I want Maven to ignore the test results of this class as they fail rarely (due to external server maintenance). But I don't want to ignore them from running as I need them for code coverage.
I've tried this configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>IntegrationTest.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
This seems to be working by ignoring the failed tests. But the problem with the above configuration is, it is ignoring the failed tests at other classes as well.
I want all the tests under Integration.java
needs to be executed but It shouldn't have any impact on the build to determine success/failure.
But, the build should fail if any test cases fail under any other Test classes other than Integration.java
答案1
得分: 1
像@khmarbaise所提到的那样,这需要由maven-failsafe
而不是surefire插件
来处理。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
通过使用maven-failsafe-plugin
,我确保了测试用例的运行以及良好的代码覆盖率,即使上游出现问题,构建也不会失败。
英文:
Like @khmarbaise has mentioned, It needs to be handled by maven-failsafe
not surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
By using maven-failsafe-plugin
I made sure the test cases run and for the good code coverage and the build will not fail even if the upstream is down.
答案2
得分: 0
**Surefire
**默认情况下包括所有以Test开头/以Test结尾/包含Tests/TestCase的测试类。
根据您的需要,可以使用排除和包含参数:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<excludes>
<exclude>DataTest.java</exclude>
</excludes>
<includes>
<include>DataCheck.java</include>
</includes>
</configuration>
</plugin>
英文:
Surefire
by default includes all test classes whose name starts with Test/ends with Test/Tests/TestCase.
You can use excludes and includes parameters as per your need :
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<excludes>
<exclude>DataTest.java</exclude>
</excludes>
<includes>
<include>DataCheck.java</include>
</includes>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论