I am writing tests for my view model and I encountered an issue, did some research and I found this on docs and using that I fixed my problem but have my question unanswered
https://developer.android.com/kotlin/flow/test#turbine
@Test
fun usingTurbine() = runTest {
val dataSource = FakeDataSource()
val repository = Repository(dataSource)
repository.scores().test {
// Make calls that will trigger value changes only within test{}
dataSource.emit(1)
assertEquals(10, awaitItem())
dataSource.emit(2)
awaitItem() // Ignore items if needed, can also use skip(n)
dataSource.emit(3)
assertEquals(30, awaitItem())
}
}
here in test {} block, it says
Make calls that will trigger value changes only within test{}
is there any reason why we should make calls that can impact value change in state flow inside test{} block, but not outside?(maybe before test block), for example above we can locate dataSource.emit(1) before test{} block, but it will not work, but I would like to know the reason why this won't work there