简体   繁体   English

使 Maven 运行所有测试,即使有些测试失败

[英]Making Maven run all tests, even when some fail

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.当第一个模块中的测试失败时,maven 将不会继续下一个项目。 I have testFailureIgnore set to true in Surefire settings, but it doesn't help.我在 Surefire 设置中将 testFailureIgnore 设置为 true,但这没有帮助。

How do I make maven run all tests regardless of earlier failures?无论早期失败如何,如何让 Maven 运行所有测试?

From the Maven Embedder documentation :来自Maven Embedder 文档

-fae , --fail-at-end Only fail the build afterwards; -fae , --fail-at-end仅在之后构建失败; allow all non-impacted builds to continue允许所有未受影响的构建继续

-fn , --fail-never NEVER fail the build, regardless of project result -fn , --fail-never永远不会使构建失败,无论项目结果如何

So if you are testing one module 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 .否则,如果您有多个模块,并且希望对所有模块进行测试(即使是那些依赖于失败的测试模块的模块),您应该运行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. -fae将继续测试失败的模块(将运行所有其他测试),但所有依赖于它的模块都将被跳过。

我刚刚找到了-fae参数,这会导致 Maven 运行所有测试并且不会在失败时停止。

Either configure Surefire with <testFailureIgnore>true</testFailureIgnore> .使用<testFailureIgnore>true</testFailureIgnore>配置Surefire

Or on the command line:或者在命令行上:

mvn install -Dmaven.test.failure.ignore=true

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>

A quick answer:快速回答:

mvn -fn test

Works with nested project builds.适用于嵌套项目构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在所有项目中运行单元测试,即使有些项目失败 - Run unit tests in all projects, even if some fail 单元测试仅在maven运行时失败 - Unit tests only fail when run by maven 当我按包运行 mvn 测试时,JUnit 测试通过,但是当我将所有包一起运行时,一些测试失败 - JUnit tests pass when I run mvn tests by packages, but when I run all the packages together some of the tests fail 由Maven运行时,集成测试随机失败或引发错误 - Integration tests randomly fail or throw error when run by maven Jbehave maven-运行所有方案,尽管有些失败 - Jbehave maven - Run all the scenarios although some fail Maven 在某些组中运行测试 - Maven run tests in some groups 按设置运行测试时单元测试失败? - Unit tests fail when tests run as set? github 工作流程:maven 测试由于缺少一些测试资源而失败,但在本地运行 - github workflows: maven tests fail when because of missing some test resources, but runs local 从maven2迁移到buildr时,为什么我的测试无法运行? - Why do my tests fail to run when migrating from maven2 to buildr? 为什么某些测试在 mvn clean install 时失败,但在我单独运行时却没有? - Why some tests fail when mvn clean install but not when I run them individually?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM