user12074594
user12074594

Reputation:

how to mock android.util.Log

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.

Upvotes: 5

Views: 4430

Answers (1)

Andrei Tanana
Andrei Tanana

Reputation: 8422

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.

Upvotes: 20

Related Questions