Sep 8, 2018 · 1 min read
Why don’t you use mockito and do something like this (instead of using tricky LiveDataTestUtil)?
LiveData<List<Node>> liveData = notesDao.getAllNotes()
liveData.observeForeover(observerMock)
assertTrue(liveData.value.isEmpty());
To instrumentations tests you should import this dependency:
androidTestImplementation “org.mockito:mockito-android:2.21.0”
If you use Kotlin you can add this function:
inline fun <reified T : Any> mock(): T = Mockito.mock(T::class.java)
And create mock like this:
val observerMock: Observer<List<Node>> = mock()
