I have ``` private val testCoroutineDispatcher = ...
# coroutines
e
I have
Copy code
private val testCoroutineDispatcher = TestCoroutineDispatcher()
  private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher)
I try to run suspend function in it
Copy code
fun runBlockingTest(block: suspend TestCoroutineScope.() -> Unit) =
    testCoroutineScope.runBlockingTest { block() }
And particular is
Copy code
dispatcherRule.runBlockingTest {
      val msg = Gallery.Effects.LoadGallery.run.invoke(this, Gallery.Deps(photoGalleryManager))
      assertThat(msg).isEqualTo(Gallery.Msg.FilesLoaded(failure))
    }
I’m getting
Copy code
This job is not completed yet
Even if I change it to:
Copy code
private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher + Job())
I still get that exception, what can I do? If I run test inside the global scope then test pass
b
Found these cases extremely difficult to solve. Only option I've found is going back to
runBlocking
.
kotlinx-coroutines-test
artifact definitely needs some work.
👍 1
Really good ressource on testing is this: https://www.droidcon.com/media-detail?video=481196790
e
I’m on the stage when I finally understand difference between job and dispatcher. But I still learning the mechanics that happens when launching coroutine in scope, threading around it and etc. The source code is available and it is the best place for truth. But I wonder if there is good course, book or resource where it is just explained step by step.
Another observation if I have next in my test it runs at least 2 seconds
Copy code
runBlocking(GlobalScope.coroutineContext) {
      val msg = suspendedFunction()      assertThat(msg).isEqualTo(Gallery.Msg.FilesLoaded(failure))
    }