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
.
val mockedFile = mockk<File>()
coEvery { mockedFile.readAsync() } returns "hello world"
coEvery { mockedFile.writeAsync(any()) } coAnswers { call ->
doAsyncWork()
Unit
}
The full list of methods with coroutine equivalents is:
当前内容版权归 Tiger Oakes 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Tiger Oakes .