Gradle – How to continue build if test is failed

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*'
}


3. Skipped the Test

Last one, skipped the entire test process.
$ gradle build -x test

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்