https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

ursus

03/30/2021, 2:35 AM
Is there a testing library other than turbine, which would work with MutableStateFlow, i.e. sideffecting type of code? (toList hangs) in rx it would looks like this
Copy code
@Test fun `doSomething should move state to FINAL`() {
    val viewModel = createViewModel(initialState = State.INITIAL)

    val testSubscriber = viewModel.state.test()
    viewModel.doSomething()

    testSubscriber.assertValues(State.INITIAL, State.FINAL)
}
g

gildor

03/30/2021, 4:13 AM
j

jw

03/30/2021, 4:33 AM
Yeah and Turbine supports MutableStateFlow's just fine. Basically if it emits, Turbine captures it.
u

ursus

03/30/2021, 7:50 AM
Thx guys, but i mentioned other than turbine. I'm just like the way rx did it better. Is there something wrong with the sample below?
e

Erik

03/30/2021, 3:07 PM
What I like about turbine is that it allows me to easily test setup assert initial state call function under test assert state(s), event(s), error(s) (call more stuff and assert more) final assertions cleanup instead of setup calls assert all the things without knowing the order of emissions w.r.t. calls final assertions cleanup
u

ursus

03/30/2021, 6:30 PM
@Erik as compared to what
g

gildor

03/31/2021, 1:45 AM
comparing to rx test subject
4 Views