I have a simplified test case where I'm calling createUserWithEmailAndPassword(...).await()
from FirebaseAuth
that leads to the exception
java.lang.IllegalStateException: This job has not completed yet
I'm using the InstantTaskExecutorRule
but this doesn't help.
Here is my simplified test class:
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Rule
import org.junit.Test
class FirebaseCoroutineTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
val auth = Firebase.auth.apply {
this.useEmulator("10.0.2.2", 9099)
}
@Test
fun testCreateUser() = runBlockingTest {
auth.createUserWithEmailAndPassword("[email protected]", "testpwd").await()
}
}
What's the correct way to do this test.
CodePudding user response:
using runBlocking
instead of runBlockingTest
solves the issue.