Coroutines and suspend functions

As MockK uses function literals to create stubs, small changes are needed to stub suspend functions. MockK provides functions prefixed with co as equivalents to other functions, such as coEvery and coAnswers.

  1. val mockedFile = mockk<File>()
  2. coEvery { mockedFile.readAsync() } returns "hello world"
  3. coEvery { mockedFile.writeAsync(any()) } coAnswers { call ->
  4. doAsyncWork()
  5. Unit
  6. }

The full list of methods with coroutine equivalents is: