I am using Espresso 2 for testing my Android app. Intermediately I see tests randomly fail with this Espresso failure message:
failed: testLongPressXXXXX (com.company.xxx.tests.testSuite.Test) ----- begin exception ----- android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.company.xxx:id/xxx_view_id View Hierarchy: +>DecorView{id=-1, visibility=VISIBLE, width=729, height=319, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} ...
Every beginning of a test the Espresso instrumentation prints out the number of activities that are still alive from a previous test:
MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: (number)
Whenever I see a failed test I always see that the number of alive activities is not 0 which led me to believe that this is the reason for this issue even though most of the time when there are live activities before a test the test still passes successfully.
When this happens the device just shows the home screen for about 10 seconds before failing. This of course happens only when I run more than one test at once.
My question is why are there live activities between tests and is there a way to make the Instrumentation wait until the activities from the previous test are finished before proceeding to the next test.
If someone has a different idea to why the tests are failing intermediately that will also be helpful as well.