Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockk in Kotlin: Argument passed to verify is not a mock

I have defined my mock as follows:

private val dal = mockk<UserDal> {
    every { insert(any()) } returnsArgument 0
}

Then, I'm trying to test it like this:

@Test
fun test() {
    userService.registerUser(userJohn)

    verify(dal).insert(check {
        assertEquals(it.firstName, "John")
    })
}

This throws an exception:

org.mockito.exceptions.misusing.NotAMockException: 
Argument passed to verify() is of type UserDal and is not a mock!
Make sure you place the parenthesis correctly!

I don't understand how it's saying that the UserDal is not a mock, when it clearly is! What is wrong with this code? How can I verify the argument fields?

like image 990
Whizzil Avatar asked Oct 19 '25 00:10

Whizzil


1 Answers

Mockito and MockK are two different, incompatible mocking frameworks. You cannot use the Mockito API to stub or verify mocks created by MockK. The reverse is true, too.

like image 57
JB Nizet Avatar answered Oct 20 '25 13:10

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!