Skipping Tests After First Failure
To skip remaining tests after first failure or error has happened set configuration parameter skipAfterFailureCount
to 1
.
Skipping Tests After the Nth Failure or Error
To skip remaining tests after the Nth failure or error has happened set configuration parameter skipAfterFailureCount
to N, where N is number greater than zero.
Prerequisite
Use maven-failsafe-plugin 2.19 or higher, JUnit 4.0 or higher, or TestNG 5.10 or higher.
If version of TestNG is lower than 5.10 while the parameter skipAfterFailureCount
is set, the plugin fails with error:
[ERROR] Failed to execute goal ...: Parameter "skipAfterFailureCount" expects TestNG Version 5.10 or higher. java.lang.NoClassDefFoundError: org/testng/IInvokedMethodListener
If version of JUnit is lower than 4.0 while the parameter skipAfterFailureCount
is set, the plugin fails with error:
[ERROR] Failed to execute goal ...: Parameter "skipAfterFailureCount" expects JUnit Version 4.0 or higher. java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.pleaseStop()V
Notices
TestNG reports skipped methods however JUnit reports skipped classes. Preferably use JUnit 4.12 or higher version which fixed thread safety issues.
Limitations
Although this feature works in forking modes as well, the functionality cannot be fully guaranteed (real first failure) in concurrent mode due to race conditions. The parameter reuseForks
should be always set to true
(which is default value), otherwise this feature won't work properly in most cases.
Other features
Re-run and skip execution
Since of 2.19.1 you can use parameters skipAfterFailureCount
and rerunFailingTestsCount
together. This is enabled by providers surefire-junit4
and surefire-junit47
. You can run again failed tests and skip the rest of the test-set if errors or failures reached skipAfterFailureCount
. Notice that failed tests within re-run phase are not included in skipAfterFailureCount
.