Android Turbine won't triggers event from liveData that converted to flow by .asFlow()

1k Views Asked by At

Turbine is very handily tool for test flows. But I have an issue when convert live data to flow like:

 fun foo(
    ): Flow<B> =
        bar().asFlow()
            .map { -> }

And then in test class: @ExperimentalCoroutinesApi val testDispatcher: TestDispatcher = StandardTestDispatcher()

@ExperimentalCoroutinesApi
val testScope: TestScope = TestScope(testDispatcher)

@Before
fun init() {
    Dispatchers.setMain(testDispatcher)
}

@Test
fun testFoo() = testScope.runTest {
    foo().test{
     val result = awaitItem()
     Assert.assertEquals(expected, result)
     awaitComplete()
    }
}

Then I got this error

After waiting for 60000 ms, the test coroutine is not completing, there were active child jobs: [ScopeCoroutine{Active}@35c3ef4a]

Previously I faced this issue and find out that in some case should awaitComplete() but it some case that will also not works.

0

There are 0 best solutions below