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

Refer this Gradle exclude some tests example

3. Skipped the Test

Last one, skipped the entire test process.


$ gradle build -x test

References

  1. Gradle – How to skip unit test
  2. Gradle – How to exclude some tests
  3. Gradle Test documentation

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
4 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
VishalRamesh KorlaArjun bmAbdul Sayeed Recent comment authors
newest oldest most voted
Abdul Sayeed
Guest
Abdul Sayeed

Thanks a lot. This is very useful.

Arjun bm
Guest
Arjun bm

Hi Mykong, Where should I use ignoreFailures settings? Here is my build.gradle. plugins { // Apply the java-library plugin to add support for Java Library id ‘java-library’ } dependencies { // This dependency is exported to consumers, that is to say found on their compile classpath. api ‘org.apache.commons:commons-math3:3.6.1’ implementation ‘com.google.guava:guava:23.2’ // This dependency is used internally, and not exposed to consumers on their own compile classpath. compile group: ‘com.google.guava’, name: ‘guava’, version: ‘25.1-jre’ compile group: ‘org.seleniumhq.selenium’, name: ‘selenium-java’, version: ‘3.14.0’ compile group: ‘io.github.bonigarcia’, name: ‘webdrivermanager’, version: ‘2.2.5’ compile group: ‘log4j’, name: ‘log4j’, version: ‘1.2.17’ compile group: ‘org.slf4j’, name: ‘slf4j-api’, version:… Read more »

Ramesh Korla
Guest
Ramesh Korla

java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at io.github.bonigarcia.wdm.WebDriverManager.(WebDriverManager.java:93)
at BaseProperties.BaseClass.initializeDriver(BaseClass.java:32)
at stepDefinations.stepDefination.initialize_the_browser_with_chrome(stepDefination.java:19)
at ?.Given Initialize the browser with Chrome(Branch.feature:5)

When I use the WebDriverManager dependency in maven project then run the TestRunner class then above error is display and doesn’t invoke the browser

Vishal
Guest
Vishal

I have one situation where I want to ignore failures on integrationTest. Is there any command line option available for gradle?
34 tests completed, 2 failed

> Task :integrationTest FAILED

FAILURE: Build failed with an exception

BUILD FAILED in 3m 41s
26 actionable tasks: 26 executed