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.

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

上一篇: Java Mutable and Immutable Objects
下一篇: Gradle Display test results in Console
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号