Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "fail fast" for junit with the maven surefire plugin?

I'm currently working on a java project using maven. We use the maven surefire plugin to run our junit suite as part of the build process.

Our test suite is rapidly growing, in both coverage and execution time. The execution time is very frustrating and time consuming when you end up waiting ten minutes to find out that a test failed in the first minute of testing.

I would like to find a way to make the build process fail upon the first error/failure in the test suite. I know that this is possible for other build tools, but I have been unable to find a way to do this with maven surefire.

I know that there is an unresolved ticket for this functionality in the surefire jira, but I'm hoping that there is an existing solution out there for this.

like image 483
Eliza Brock Marcum Avatar asked Dec 17 '09 19:12

Eliza Brock Marcum


People also ask

How does Maven failsafe plugin work?

The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.

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.

Which is the Maven plugin for running JUnit tests?

The Maven Surefire Plugin 2.22. 0 (or newer) provides native support for JUnit 5. If we want to use the native JUnit 5 support of the Maven Surefire Plugin, we must ensure that at least one test engine implementation is found from the classpath. We can run our unit tests by using the command: mvn clean test.

Which Maven plugin triggers the test case?

Work Flow Using The Maven Surefire Plugin As TestNG has the capability to select and execute particular test scripts or suites, we are integrating this with Maven using the Maven Surefire plugin.


2 Answers

As of September 6th 2015 it appears there is, -Dsurefire.skipAfterFailureCount=1.

As of October 19th 2015 version 2.19 has been released.

like image 119
Captain Man Avatar answered Sep 29 '22 20:09

Captain Man


As far as I know, no, and this really requires the resolution of SUREFIRE-580. If you want to make this happen faster, you should at least vote for the issue and, optionally, submit a patch ;)

like image 25
Pascal Thivent Avatar answered Sep 29 '22 20:09

Pascal Thivent