Migrating from Mockito #
Learn how to use MockK by seeing equivalents to functions in Mockito.
- Create a mock
- The similarities and differences in creating mocks between Mockito and MockK.
- `when` and `do*`
when(x).thenReturn(y)
,doReturn
, and more.- `eq`
- Mockito’s
eq
,refEq
, andsame
argument matchers. - `any*`
- The “any” family of matchers:
any
,anyBoolean
,anyByte
,anyChar
,anyDouble
,anyFloat
,anyInt
,anyLong
,anyObject
,anyShort
, andanyString
. - `verify`
verify
that a method was called.- `argThat`
- Porting custom matchers with
argThat
- `ArgumentCaptor`
- Capturing arguments to check them later.
- `void` methods
- MockK makes it easier to mock methods that return
void
.