How can I ignore test failures with the gradle robolectric plugin?
Asked Answered
W

3

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.

Walkthrough answered 7/7, 2014 at 15:49 Comment(2)
If the failed tests set is small you can mark them @Ignore to fix timesBanting
#20142986 Follow this link.And it may help you.Arizona
B
14

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

testOptions {
    unitTests.all {
        setIgnoreFailures(true)
    }
}
Bashaw answered 23/3, 2016 at 20:25 Comment(3)
Welcome to Stack Overflow. Would you be able to add a reference to the documentation for this please?Rist
@Rist 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.javaBashaw
after i found out, where to set this, i m thankful for your answer! android { testOptions { unitTests.all { setIgnoreFailures(true) } } }Alley
E
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

Episiotomy answered 7/7, 2014 at 16:8 Comment(1)
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.Brawner
F
0

try without '='

robolectric {
    ignoreFailures true
}
Faction answered 22/1, 2015 at 14:15 Comment(3)
jermaine1904, how to use it in new Android Studio 1.1.0 for example with Robolectric 3.0. From last updates we don't use plugin, so the code above doesn't work?Spherical
do you run your tests in android studio or via console?Faction
jermaine1904@ in Android Studio, tab Terminal (like from usual console, how I understand)Spherical

© 2022 - 2024 — McMap. All rights reserved.