Java 使 Maven 运行所有测试,即使有些测试失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4174696/
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
Making Maven run all tests, even when some fail
提问by ripper234
I have a project with several modules. When all tests pass, Maven test runs them all.
我有一个包含多个模块的项目。当所有测试都通过时,Maven 测试会运行它们。
When tests fail in the first module, maven will not continue to the next project. I have testFailureIgnore set to true in Surefire settings, but it doesn't help.
当第一个模块中的测试失败时,maven 将不会继续下一个项目。我在 Surefire 设置中将 testFailureIgnore 设置为 true,但这没有帮助。
How do I make maven run all tests?
如何让 maven 运行所有测试?
采纳答案by ripper234
I just found the "-fae" parameter, which causes Maven to run all tests and not stop on failure.
我刚刚找到了“-fae”参数,它会导致 Maven 运行所有测试并且不会在失败时停止。
回答by Pascal Thivent
Can you test with surefire 2.6 and either configure surefire with testFailureIgnore=true
. Or on the command line:
您可以使用 surefire 2.6 进行测试,并使用testFailureIgnore=true
. 或者在命令行上:
mvn install -Dmaven.test.failure.ignore=true
回答by nybon
Try to add the following configuration for surefire plugin in your pom.xml of root project:
尝试在根项目的 pom.xml 中为 surefire 插件添加以下配置:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
回答by despot
From the Maven Embedder documentation:
-fae
,--fail-at-end
Only fail the build afterwards; allow all non-impacted builds to continue
-fn
,--fail-never
NEVER fail the build, regardless of project result
-fae
,--fail-at-end
仅在之后构建失败;允许所有未受影响的构建继续
-fn
,--fail-never
永远不要让构建失败,无论项目结果如何
So if you are testing onemodule than you are safe using -fae
.
因此,如果您正在测试一个模块,那么使用-fae
.
Otherwise, if you have multiple modules, and if you want all of them tested (even the ones that depend on the failing tests module), you should run mvn clean install -fn
.-fae
will continue with the module that has a failing test (will run all other tests), but all modules that depend on it will be skipped.
否则,如果您有多个模块,并且希望对所有mvn clean install -fn
模块进行测试(即使是那些依赖于失败测试模块的模块),则应该运行. -fae
将继续测试失败的模块(将运行所有其他测试),但所有依赖于它的模块都将被跳过。
回答by rustyx
A quick answer:
快速回答:
mvn -fn test
Works with nested project builds.
适用于嵌套项目构建。