In the documentation (highlighted by me):
If the exceptions thrown by the Android APIs in android.jar are problematic for your tests, you can change the behavior so that the methods return zero or zero instead by adding the following top-level build.gradle file to your project:
android { ... testOptions { unitTests.returnDefaultValues = true } }
Caution: setting the returnDefaultValues property to true should be done with caution. The null / zero return values may introduce regressions in your tests, which are difficult to debug and may skip tests with errors. Use it only as a last resort.
source share