简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM