title: Unit testing a Kotlin coroutine with delay
body: <p>I'm trying to unit test a Kotlin coroutine that uses <code>delay()</code>. For the unit test I don't care about the <code>delay()</code>, it's just slowing the test down. I'd like to run the test in some way that doesn't actually delay when <code>delay()</code> is called.</p>
  
  <p>I tried running the coroutine using a custom context which delegates to CommonPool:</p>
  
  <pre><code>class TestUiContext : CoroutineDispatcher(), Delay {
      suspend override fun delay(time: Long, unit: TimeUnit) {
          // I'd like it to call this
      }
  
      override fun scheduleResumeAfterDelay(time: Long, unit: TimeUnit, continuation: CancellableContinuation&lt;Unit&gt;) {
          // but instead it calls this
      }
  
      override fun dispatch(context: CoroutineContext, block: Runnable) {
          CommonPool.dispatch(context, block)
      }
  }
  </code></pre>
  
  <p>I was hoping I could just return from my context's <code>delay()</code> method, but instead it's calling my <code>scheduleResumeAfterDelay()</code> method, and I don't know how to delegate that to the default scheduler.</p>