我想模拟一个挂起函数,使其永远不会返回任何结果。与此类似的是Single.never()
的使用。
有可能吗?
我的团队通过从不调用resume()
的suspendCancellableCoroutine
实现了这一点。类似这样的东西:
suspend fun never(): Nothing = suspendCancellableCoroutine { }
对于Mockk,我做了以下操作。请确保切换到非测试调度程序,这样就不会跳过延迟。
coEvery { mockApi.getEmployees() } coAnswers {
withContext(Dispatchers.Unconfined) { delay(Long.MAX_VALUE) }
Success
}