coroutinedispatcher
12/06/2022, 9:16 PMsuspend fun timeDifference() : Int {
val x = System.currentTimeMillis()
delay(5.toDuration(DurationUnit.SECONDS)
val y = System.currentTimeMillis()
return TimeUnit.SECONDS.ofSecond(y - x)
}
and then write a test for this:
@Test
fun test() = runTest {
val result = timeDifference()
advanceUntilIdle()
printLn(result)
}
Is it true that the output would be inconsistent? I tried it a lot of times and it doesn’t print the “predicted result” (in this case 5 seconds) but rather some other number.kevin.cianfarini
12/06/2022, 10:06 PMdelay
and debounce
won’t reflect wall time.bezrukov
12/06/2022, 10:47 PMcoroutinedispatcher
12/10/2022, 11:35 AM