Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does android.unitTests.returnDefaultValues work?

I know what having the following in an Android project's build.gradle is supposed to do. But how does it work? And what exactly are the default values returned? How do they compare with "real" values?

android {
    // ...
    testOptions { 
        unitTests.returnDefaultValues = true
    }
}
like image 374
Julian A. Avatar asked Aug 26 '15 21:08

Julian A.


1 Answers

Per the documentation (emphasis added):

If the exceptions thrown by Android APIs in the android.jar are problematic for your tests, you can change the behavior so that methods instead return either null or zero by adding the following configuration in your project's top-level build.gradle file:

android {
  ...
  testOptions {
    unitTests.returnDefaultValues = true
  }
}

Caution: Setting the returnDefaultValues property to true should be done with care. The null/zero return values can introduce regressions in your tests, which are hard to debug and might allow failing tests to pass. Only use it as a last resort.

like image 162
plátano plomo Avatar answered Sep 29 '22 05:09

plátano plomo