Surefire rerun failing tests not working

Just to add to Wim Rutgeerts's answer - rerunFailingTestsCount must be in the configuration section, not in properties, like this:

<configuration>
    <rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>

In my case with maven-surefire-plugin 2.19.1 it worked this way. When it was in properties it did not work.


Although that is missing from the documentation, the parameter rerunFailingTestsCount was introduced in version 2.18 of the Maven Surefire Plugin, as mentioned in SUREFIRE-1087. Since you're using the default version of 2.12.4 (that comes from the Super POM), that option is not available.

Therefore, the fix is simply to update the Surefire version to a version that is at least 2.18; for example, the latest, which is currently 2.19.1:

<pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19.1</version>
    </plugin>
  </plugins>
</pluginManagement>

Note that this parameter only works with JUnit 4+ (which is your case, since you have JUnit 4.12).


Instead of using the command line property -Dsurefire.rerunFailingTestsCount=2, you can also define it in the pom in the properties section

 <properties>
    <surefire.rerunFailingTestsCount>2</surefire.rerunFailingTestsCount>
 </properties>