Sunday, April 8, 2018

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

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...