This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

** Question: Make Maven run all tests even if some tests fail **

I have a project with multiple modules. When all tests pass, the Maven tests will all run.

When a test fails in the first module, Maven will not proceed to the next project. I set testFailureIgnore to true in my Surefire Settings, but that didn’t help.

How do I get Maven to run all tests, regardless of what, or whether, previous failures were?

Answer 1:

Try adding the following configuration to the Surefire plug-in in the pom.xml of the root project:


<project>[...].<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <testFailureIgnore>true</testFailureIgnore>
        </configuration>
      </plugin>
    </plugins>
  </build>[...].</project>
Copy the code

Answer 2:

From the Maven Embedder document:

-fae, -fail-at-end allows all unaffected builds to continue only after they have failed, such as ABCD, where D depends on C. Since C failed, run this command at this point and the program will build AB

-fn, -fail-never never causes a build to fail, no matter what the outcome of the project

In summary, it is safe to use -fae if you are testing a module.

Otherwise, if you have multiple modules and are testing all of them (even modules that rely on failed test modules), you should run MVN Clean Install-fn. – FAE will continue to test the failed module (all other tests will be run), but will ignore all modules that depend on that module.