Kshitij Patil
05/03/2021, 3:32 PMMutableSharedFlow
with replay=0
? I'm using turbine for testing Kotlin Flows and I managed to write tests for MutableStateFlow
, but the same emitted values doesn't work for SharedFlows.Erik
05/04/2021, 12:22 PMErik
05/04/2021, 12:22 PMsharedFlow.test {
Erik
05/04/2021, 12:23 PM}
Kshitij Patil
05/04/2021, 12:27 PMtest { }
block only?Erik
05/04/2021, 12:37 PMErik
05/04/2021, 12:37 PMKshitij Patil
05/04/2021, 1:29 PMSharedFlow
and StateFlow
, Channels are considered to be low level APIs. So, I'm trying to use MutableSharedFlow
to build a mock class wrapping some state and I use public methods of this clas to mutate that state, thus, transformed objects are emitted to a private MutabelSharedFlow
and a Public Flow is where I'm expecting those changes to appear. So I was calling that public method in @Before
section and was expecting those events to appear in SharedFlow
unit test. Will try your suggested approach and let you know how it goes.
Thanks!Erik
05/04/2021, 2:18 PMursus
05/04/2021, 5:30 PMKshitij Patil
05/05/2021, 6:02 AMErik
05/05/2021, 6:05 AMKshitij Patil
05/05/2021, 7:15 AMErik
05/05/2021, 8:06 AMlaunch
Erik
05/05/2021, 8:08 AMflow.test {
// assert initial behaviour, e.g. emission(s) or error
// call stuff that should make the flow do something
// assert that the flow does it
// repeat previous steps as often as you like
// assert final state, e.g. flow completed or flow does nothing more
}
Kshitij Patil
05/05/2021, 8:41 AMtest { }
is run within same Job and we should mainly be doing collect operations there.Erik
05/05/2021, 10:33 AMErik
05/05/2021, 10:35 AMErik
05/05/2021, 1:56 PMtake
values), and assert that the list is as expected.Kshitij Patil
05/05/2021, 3:57 PMSharedFlow
I needed. Will be useful in some complex scenarios I have in the codebase.