I am running Espresso tests on my Android application. The test is flaky. It can reliable assert that the data-model is updated. My problem is that the ViewMatchers can\'t m
Espresso does waitForIdle
before executing view checks. waitForIdle
goes thought IdlingRegistry
and waits until every IdlingResource
is idle.
LoopingIdlingResource
is used in Espresso by default. It waits until looper doesn't have messages in queue, which means that it is idle.
However DataBinding
uses different approach to schedule an update, it uses Choreographer.postFrameCallback
. So updates are not posted into looper queue and Espresso will not wait for them.
In such cases you should register your own IdlingResource. You can find in googlesamples/android-architecture-components
nice sample how to implement custom DataBindingIdlingResource and DataBindingIdlingResourceRule that will sets the idle resource before executing tests.
So you have to copy these classes DataBindingIdlingResourceRule and DataBindingIdlingResource into your tests.
And add the following rule into your test class:
@Rule
@JvmField
val dataBindingIdlingResourceRule = DataBindingIdlingResourceRule(activityRule)