I am using Turbine to test my DAO that has a funct...
# squarelibraries
g
I am using Turbine to test my DAO that has a function returning a Flow that observes a table and returns its elements over time. I can’t manage to do something like this:
Copy code
@Test
fun testCountStream() = runTest {
    dao.countStream().test {
        dao.insert(...)
        assertEquals(1, awaitItem().size)

        dao.insert(...)
        assertEquals(2, awaitItem().size)

        cancelAndIgnoreRemainingEvents()
    }
}
Certainly, my problem lies with the library’s syntax. I’ve been looking at the documentation and doing some experiments, but I haven’t had any success. Can someone give me a tip? Thanks 🙌
s
I'm sorry, but what's the question here? Your code looks fine to me
g
it will fail with: Expected :2 Actual :1
s
hmm your turbine usage looks correct to me. I'd suggest investigating if your SQL queries are correct.
a
distinctUntilChange()
could also help if this is a case of duplicate emissions from the database
g
the SQL is correct too, running the app is fine all works, but the tests I can’t make them work 😅
well, I was missing an await in the beginning:
Copy code
assertEquals(0, awaitItem().size)
🤦‍♂️