2

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?

4

1 回答 1

4

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.

于 2019-08-19T06:15:31.157 回答