Espresso freezing on view with looping animation Espresso freezing on view with looping animation android android

Espresso freezing on view with looping animation


Yes, the problem you are having with the test is due to the animation.

The only solution I can think of is indeed to turn off the infinite animations.

In general it is a good idea to turn off animations when running functional tests, as they always introduce some flakiness.

A bit of background:

The UI thread is never idle from Espresso's perspective, because the message queue always contains an event that is scheduled for handling closer than the threshold used to determine if thread is idle.

When you look at QueueInterrogator, you can see that it's determineQueueState() returns TASK_DUE_SOON when message queue contains an event that is scheduled for handling in less than 16ms. UiController will only continue execution when all idle conditions are fulfilled, in case of the QueueInterrogator this is only the case if the message queue is empty or the next message is scheduled for handling in 16ms or later.

Animations will invalidate the View they are transforming, and this will trigger a new view hierarchy traversal by the Choreographer. And this trigger message coming from ViewRoot to the Choreographer is what is keeping your UI thread message queue not idle.