Sometimes it is desirable to create some resources in the test and automatically release them when the test is completed using a Job CompletionHandler from coroutine context. In the runBlocking coroutine context the registered job CompletionHandler is called, but not in the runBlockingTest. Is it right to expect that when runBlockingTest stop being experimental the registered CompletionHandler will be called?
@Test
fun should_invoke_CompletionHandler() {
var wasCalled = false
runBlockingTest {
coroutineContext[Job.Key]?.invokeOnCompletion {
wasCalled = true
}
}
Truth.assertThat(wasCalled).isEqualTo(true)
}