Gradle How to continue build if test is failed
By:Roy.LiuLast updated:2019-08-17
By default, the Gradle build process will be stopped and failed if any unit test is failed.
$ gradle build :clean :compileJava :processResources :classes :compileTestJava :processTestResources UP-TO-DATE :testClasses :test com.mkyong.example.TestExample > test_example FAILED java.lang.Exception at TestExample.java:9 //... 3 tests completed, 1 failed :test FAILED //... BUILD FAILED // <-------------- see status
In this article, we will show you a few ways to continue the build process even if the test process is failing.
1. Ignore Failed Test
Try ignoreFailures settings.
build.gradle
test { ignoreFailures = true
Now, the build will continue even the test process is failing.
$ gradle build :clean :compileJava :processResources :classes :compileTestJava :processTestResources UP-TO-DATE :testClasses :test com.mkyong.example.TestExample > test_example FAILED java.lang.Exception at TestExample.java:9 //... 3 tests completed, 1 failed :test FAILED //... :check //ignore test failed, continue the build :build BUILD SUCCESSFUL // <-------------- see status
2. Exclude the Failed Test
Find out the failed unit test and exclude it:
build.gradle
test { exclude '**/ThisIsFailedTestExample.class' exclude '**/*FailedTestExample*'
Refer this Gradle exclude some tests example
3. Skipped the Test
Last one, skipped the entire test process.
$ gradle build -x test
References
From:一号门
Previous:Java Mutable and Immutable Objects
COMMENTS