79601828

Date: 2025-05-01 12:15:20
Score: 0.5
Natty:
Report link

OK, I'm adding this here because I was still getting the error even when using the answers here. Greg Ennis' answer looks to cover my case but it didn't work.

The problem is that mocking Log.e gives an error when testing resulting in a "Log.e not mocked" error ... and other levels can too, even with the mock. The issue is that there are multiple methods you need to mock, as you can see below (two version of Log.e, and the error in testing occurs when you are hitting the Log.e which you haven't mocked!):

This is for Kotlin, and it goes in your @Before block in the testing class:

        mockkStatic(Log::class)
        every { Log.v(any(), any()) } returns 0
        every { Log.d(any(), any()) } returns 0
        every { Log.i(any(), any()) } returns 0
        every { Log.e(any(), any()) } returns 0
        every { Log.e(any(), any(), any()) } returns 0
        every { Log.w(any(), any<String>()) } returns 0
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Before
  • Low reputation (0.5):
Posted by: MacD