I am using Espresso 2 for testing my Android app. Intermediately I see tests randomly fail with this Espresso failure message:
failed: testLongPressXXXXX (com.compan
This question was asked a while ago but since this still seems to be relevant I thought I'd share what I found. I am facing a similar problem - AmbiguousViewMatcherException on Views that have a unique id, different tests failing randomly - probably due to Activities not being destroyed.
This seems to be a known issue and should be addressed in the next release (see here: https://github.com/google/android-testing-support-library/issues/16). Apparently onDestroy() and isFinishing() are not called reliably after each test so you might not get a fresh Activity every time or even end up with two Activities on top of each other.
Until they fix it I've decided not to waste my time on a workaround but starting using Genymotion emulators which solved my problem - possibly because they run faster than the built-in ones in Android Studio (as was suggested here).