5

I'm using the robolectric-gradle-plugin for robolectric unit tests. I don't want to fail a build on failed tests. Is there a way in DSL or a property not to fail a test on the build similar to -DtestFailureIgnore=true on the Surefire Maven plugin?

I've tried:

robolectric {
    ignoreFailures = true
}

and

robolectric {
    ignoreFailure = true
}

and -DignoreFailure=true on the command line.

I can't seem to find any documentation of how to do this, or any reference to ignoring tests in the source code.

Community
  • 1
  • 1
C. Ross
  • 31,137
  • 42
  • 147
  • 238
  • If the failed tests set is small you can mark them @Ignore to fix times – Eugen Martynov Jul 07 '14 at 16:38
  • https://stackoverflow.com/questions/20142486/dont-fail-the-gradle-build-if-a-test-is-failing-with-the-gradle-android-test-pl/25587012#25587012 Follow this link.And it may help you. – Kumar Gouda Feb 21 '23 at 13:16

3 Answers3

14

answering very old question, so that it might help others who bump into here

testOptions {
    unitTests.all {
        setIgnoreFailures(true)
    }
}
Surge
  • 153
  • 1
  • 6
  • Welcome to Stack Overflow. Would you be able to add a reference to the documentation for this please? – Dezza Mar 23 '16 at 20:45
  • @Dezza no trace of documentation for this property. I have gone through the gradle version 1.5.0 source code and found this solution. Property _ignoreFailures_ is defined in `Test.java`, which is accessible via `UnitTestOptions.all()` of `TestOptions.java` – Surge Mar 23 '16 at 21:42
  • 1
    after i found out, where to set this, i m thankful for your answer! `android { testOptions { unitTests.all { setIgnoreFailures(true) } } }` – fky May 04 '16 at 09:10
1

I would suggest not to continue building an APK if there are any failing tests. But if you want to build an APK without testing the only way right now is to use gradle build -x test[1]. This will run build and not run any tests.

[1]http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:excluding_tasks_from_the_command_line

Hiemanshu Sharma
  • 7,702
  • 1
  • 16
  • 13
  • The reason to continue the build, is if other things will run later against the APK. For example: Integration tests, FindBugs, Reports etc. Stopping too soon could prevent these. – Stephen M -on strike- Dec 04 '18 at 16:51
0

try without '='

robolectric {
    ignoreFailures true
}