Hi, I have an issue in my unit tests where the Liv...
# android
k
Hi, I have an issue in my unit tests where the LiveData does not dispatch the value to the observer registered using
LiveData.observeForever
. Does anyone has an idea as to what might be causing that?
a
Livedata only fires if it had an observer in a valid lifecycle state, it's probably your lifecycle owner on that observe. Personally I wouldn't be using livedata's in a unit test at all but, that's obviously your call.
m
Have you added this?
*@get*:Rule
val testInstantTaskExecutorRule: TestRule = InstantTaskExecutorRule()
k
I did figure it out. My LiveData was using a separate Coroutine dispatcher than the one used by the tests. That was the problem. @Alex Prince LiveData works with observers that are not lifecycle bound. It is not limited to lifecycle bound observers.