• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Mockk verify is trying to verify Log.d() which is never been called

Resolved: Mockk verify is trying to verify Log.d() which is never been called

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

So, I have written unit test as follows. Which basically calls a method in Viewmodel class.
Method in Viewmodel
As you can see, I am trying ti verify if 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
I have mock AppUtility like 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 function Log.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:
You could also inject a wrapper around your Log and mock that one, like you do with AppUtility.

If you have better answer, please add a comment about this, thank you!

android kotlin mockk mockk-verify unit-testing
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.