Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 'test' command that only runs the tests that failed

Tags:

maven

Is there a way to call the maven 'test' command that only runs the tests that failed the last time it was called?

like image 717
Glide Avatar asked Jul 11 '12 21:07

Glide


People also ask

How do I run only failed test cases in Maven?

During development, you may re-run failing tests because they are flaky. To use this feature through Maven surefire, set the rerunFailingTestsCount property to be a value larger than 0. Tests will be run until they pass or the number of reruns has been exhausted.

How do I run a specific test case in Maven?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.

Which Maven command is used to run test cases?

mvn test This command is used to run the test cases of the project using the maven-surefire-plugin .

How do I skip failed test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.


1 Answers

Try using the surefire plugin's runOrder parameter. It doesn't look like it has an ${expression} allowing you to change the property from the command line, so I would roll my own:

... POM stuff here....
<properties>
    <!-- plugin's default value for this param -->  
    <surefire.test.runOrder>filesystem</surefire.test.runOrder>
</properties>
....
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <runOrder>${surefire.test.runOrder}</runOrder>
  </configuration>
</plugin>
....

Then you may choose the setting you want at the command line:

mvn -Dsurefire.test.runOrder=failedfirst test (or package or whatever phase you want).

like image 112
user944849 Avatar answered Oct 11 '22 16:10

user944849