Question:
So, I have written unit test as follows. Which basically calls a method in Viewmodel class.clearCache()
function is called.And when I run the test I get following error. And it works(successful) as soon as I delete the line
Log.d(TAG, "clearCache:e ")
.Error stack trace
private val appUtilityMock: AppUtility = mockk(relaxed = true)
.I am not sure what is going wrong. Please help me understand. I am using MockK for testing.
Answer:
You are calling the functionLog.d
, but this is in android.util.Log
and therefore not available in your tests. See the documentation for more information. You can add a default implementation by adding this to your gradle file in the android {
part:AppUtility
.If you have better answer, please add a comment about this, thank you!