Why MockK Why MockK MockK is a mocking framework built in Kotlin to be used with Kotlin programs. Because MockK is written in Kotlin, it has first-class support for Kotlin langu...
Verify that functions were called Verifying dependencies Verifying that any mock functions is never called Verifying that a function is never called Verifying a function is call...
Tips Tips In this section we present a number of tips that we have collected over the course of using MockK in the real world. Chains Exclude Timeout Timeouts # Return `...
when and do* thenReturn /doReturn thenThrow /doThrow doNothing thenAnswer /then /doAnswer Consecutive calls Coroutines when and do* Mockito provides two similar ap...
Create many mocks quickly with annotations Options Spies Create many mocks quickly with annotations Sometimes you will need to create many mocks in your test class. As each mo...
Create a mock Create a mock The syntax to create a mock is very similar in Mockito and MockK. However, the behaviour is slightly different. // Mockito val mockedFile = mock...
Stub out behaviour Stub out behaviour Your Kotlin classes often depends on other objects and functions when running. When you are writing tests for your classes, you only want t...
Run assertions with an argument Arrays and data classes Nullable arguments Coroutines Run assertions with an argument There are some special argument matchers that can only b...
Automatically stub by relaxing Automatically stub by relaxing If a method has not been stubbed, MockK will throw an error if it is called. This is designed to help make your tes...