A Gamal
01/17/2019, 4:45 PMTestCoroutineContext
. In unit testing, should I init it in classes that have CoroutineContext
in the constructor?streetsofboston
01/17/2019, 5:44 PMclass MyTestSuite : CoroutineScope {
private val job = SupervisorJob()
private val testCoroutineContext = TestCoroutineContext()
override val coroutineContext = job + testCoroutineContext
@ AfterEach
fun tearDown() { job.cancel() }
@ Test
fun myTest() {
...
...
launch {
val result = myCodeUnderTest()
assertThat(result, `is`(expectedValue))
}
...
testCoroutineContext.triggerActions()
...
testCoroutineContext.advanceTimeBy(500L)
...
}
...
}
A Gamal
01/17/2019, 9:01 PM