4

I.m using a mockk library in kotlin, and in tests, I have the following exception:

java.lang.RuntimeException: Method getStackTraceString in android.util.Log not mocked. See http://g.co/androidstudio/not-mocked for details.

I can't find a solution for that.

Kevin
  • 16,549
  • 8
  • 60
  • 74

1 Answers1

16

You have to add

testOptions { 
  unitTests.returnDefaultValues = true
}

in android section in your build.gradle file. It will mock some call to Android platform. Please note that it just return default values.

In the new gradle plugin this property was renamed to isReturnDefaultValues.

Andrei Tanana
  • 7,932
  • 1
  • 27
  • 36
  • 4
    please note that as [The comment in this answer](https://stackoverflow.com/a/42653151/9735961) pointed out, this is **NOT** mocking some call to Android platform, but just return default values, which might cause problems as "the null/zero return values can introduce regressions in your tests". – Samuel T. Chou Aug 31 '21 at 08:53
  • 1
    The unitTests variable name has changed to `isReturnDefaultValues`: https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/UnitTestOptions#isreturndefaultvalues – robotsquidward Nov 11 '21 at 13:36