title: Kotlin coroutine unit test fails with "Module with the Main dispatcher had failed to initialize"
body: <p>While running unit test for kotlin suspend method which uses <code>withContext(Dispatchers.Main)</code> the test method fails with below exception:</p>
  
  <p>My coroutine lib versions are <strong>kotlinx-coroutines-core:1.1.1</strong> and <strong>kotlinx-coroutines-android:1.1.1</strong></p>
  
  <p>Example:</p>
  
  <pre><code>suspend fun methodToTest() {
          withContext(Dispatchers.Main) {
             doSomethingOnMainThread()
                  val data = withContext(Dispatchers.IO) {
                      doSomethingOnIOThread()
                  }
          }
      }
  </code></pre>
  
  <p>Also, when I remove the <code>withContext(Dispatchers.Main)</code> it works fine.</p>
  
  <pre><code>java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used
  
  at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MainDispatchers.kt:79)
  at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:54)
  at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:373)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:152)
  at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
  </code></pre>