tseisel
09/16/2019, 10:15 AMTestObserver
to test coroutines Flow
?gildor
09/16/2019, 10:18 AMMatej Drobnič
09/16/2019, 10:37 AMgildor
09/16/2019, 10:39 AMassert()
extensions for example, but do you really need one? maybe you need some particular feature of TestObservertseisel
09/16/2019, 11:44 AMawaitCount(Int)
) and perform assertions on them.
What are your recommendations for testing simpler flows ? Collect as List
with toList
and perform assertions on the list ?streetsofboston
09/16/2019, 12:02 PMfun <T> Flow<T>.test(): TestCollector<T>
and a new class TestCollector<T>
. I'd open a PR or issue to add this to the library. (It would function like an Rx TestObserver/TestSubscriber)Paul Woitaschek
09/16/2019, 12:27 PMrunBlockingTest{
val firstThreeItems = withTimeout(1000) {
flowOf(1, 2, 3, 4).take(3).toList()
}
assertThat(firstThreeItems)...
}
jw
09/16/2019, 1:08 PM@Test fun queryNotNotifiedAfterCancel() = runTest {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES, MAPPER)
.asFlow()
.test {
expectItem().assert {
hasRow("alice", "Alice Allison")
hasRow("bob", "Bob Bobberson")
hasRow("eve", "Eve Evenson")
}
cancel()
db.employee(Employee("john", "John Johnson"))
expectNoMoreEvents()
}
}
streetsofboston
09/16/2019, 1:30 PMflow
under test doesn’t complete, a terminating function on it never resumes. There is where something like a TestCollector or @jw’s example can help out.Vsevolod Tolstopyatov [JB]
09/16/2019, 5:39 PMMarcelo Hernandez
08/04/2020, 12:31 AMPaul Woitaschek
08/05/2020, 5:20 PM