ilya-gh
05/20/2019, 12:49 PMdelay
in the following code:
class A(val coroutineContext: CoroutineContext = EmptyCoroutineContext) {
fun work(): String {
val result = runBlocking(coroutineContext) {
delay(3000)
return "some_result"
}
return result
}
}
@Test
fun `tests work`() {
val result = A().work()
assertEquals("some_result", result)
}
If a pass TestCoroutineContext()
to runBlocking the delay
is ignored as expected. However, It’s deprecated in favor of TestCoroutineScope.
TestCoroutineScope. However If I pass TestCoroutineScope the test never finishes:
@Test
fun `tests work`() {
val result = A(TestCoroutineScope(TestCoroutineDispatcher()).coroutineContext).work()
// never reaches here
assertEquals("some_result", result)
}
What I am missing?gildor
05/20/2019, 1:01 PM