title: Unit testing coroutines runBlockingTest: This job has not completed yet
body: <p>Please find below a function using a coroutine to replace callback : </p>
  
  <pre><code>override suspend fun signUp(authentication: Authentication): AuthenticationError {
      return suspendCancellableCoroutine {
          auth.createUserWithEmailAndPassword(authentication.email, authentication.password)
              .addOnCompleteListener(activityLifeCycleService.getActivity()) { task -&gt;
                  if (task.isSuccessful) {
                      it.resume(AuthenticationError.SignUpSuccess)
                  } else {
                      Log.w(this.javaClass.name, "createUserWithEmail:failure", task.exception)
                      it.resume(AuthenticationError.SignUpFail)
                  }
              }
      }
  }
  </code></pre>
  
  <p>Now I would like to unit testing this function. I am using Mockk : </p>
  
  <pre><code>  @Test
    fun `signup() must be delegated to createUserWithEmailAndPassword()`() = runBlockingTest {
  
        val listener = slot&lt;OnCompleteListener&lt;AuthResult&gt;&gt;()
        val authentication = mockk&lt;Authentication&gt; {
          every { email } returns "email"
          every { password } returns "pswd"
        }
        val task = mockk&lt;Task&lt;AuthResult&gt;&gt; {
          every { isSuccessful } returns true
        }
  
        every { auth.createUserWithEmailAndPassword("email", "pswd") } returns
            mockk {
              every { addOnCompleteListener(activity, capture(listener)) } returns mockk()
            }
  
      service.signUp(authentication)
  
        listener.captured.onComplete(task)
      }
  </code></pre>
  
  <p>Unfortunately this test failed due to the following exception : <code>java.lang.IllegalStateException: This job has not completed yet</code> </p>
  
  <p>I tried to replace <code>runBlockingTest</code> with <code>runBlocking</code> but the test seems to wait in an infinite loop.</p>
  
  <p>Can someone help me with this UT please?</p>
  
  <p>Thanks in advance</p>