Did anyone try using `getOrAwayValue()` (the helper function from Google's testing samples) on `Flow...
f
Did anyone try using
getOrAwayValue()
(the helper function from Google's testing samples) on
Flow#asLiveData()
? I'm not getting a value.
It works if I use
UnconfinedTestDispatcher
instead of
StandardTestDispatcher
g
Created flow probably asynchronous, so you just get empty live data, this why unconfined dispatcher helps Why do you convert it to live data?
f
I use LiveData for the automatic handling of the activity lifecycle
g
Why you cannot do the same with flow?
I just really think that there is no valid reasons anymore to use livedata if you already has flow in the project
f
Yea I'm considering switching to Flow but I still didn't just want to ignore the problem. But we found the solution eventually.
g
I wouldn't call it a problem, rather lack of proper testing facilities for live data. Testing reactive properties with non reactive tests is always painful and unreliable, because they become testable only when some kind Unconfined dispatchers/schedulers are used for all involved components
f
Google has a LiveData TestUtil for that which seems to work
The
getOrAwaitValue
one
But it seems to need
UnconfinedTestDispatcher
to work
g
Yes, of course
My point is that getOrAwaitValue is not the best way to test any reactive properties, in any framework
f
Thank you. I will probably replace LiveData for Flow in the UI layer earlier or later. I just wish I would understand why
asLiveData
needs
UnconfinedTestDispatcher
to work.