Hi, I have a problem trying to write a unit test t...
# coroutines
l
Hi, I have a problem trying to write a unit test that combines
LiveData
and Coroutines, so I'm not sure if this is the best channel for this question, but it seems to be more about coroutines. If I understand correctly for
LiveData
the best practice is to use the
InstantTaskExecutorRule
and for coroutines is to set as the main dispatcher a single thread executor before the test and reset it after. Now with this setup I can write correct tests while testing one or the other at a time, but I have a
LiveData
that is created from a
Flow
using the builder
androidx.lifecycle.liveData
that runs on the Main dispatcher. Now when I observe the
LiveData
the observer is not called instantly since even if the
InstantTaskExecutorRule
uses the current thread as main thread the updates run on the coroutines Main dispatcher which is another thread. Some suggestion on how to wait that all the updates are delivered to the observer? Also the
Flow
has also a
onCompletion
action registered and I need to wait that also that is executed.