Reputation: 4780
I have a test class in which I have six espresso tests. If I run the test class, three pass, three fail.
If I run each test individually all tests pass as expected. Some of these have race conditions (api request) so I understand those and Im looking at using the idlingResource, however others do not, for example there's a noMatchingViewException android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Sort by best match"
which is incorrect as the view is there and is found when test is run on it's own, which then passes as expected.
I'm just wondering anyone has come across this and if so could you share how to fix it.
Upvotes: 5
Views: 1886
Reputation: 61
make sure to reset the App-State if one of your tests is making changes and a second test is relying on a vanilla state. You can use @Before and @After Annotations to set/reset the app state
check for race-conditions and async processes in your app
on slow test devices a perform(click()) can sometimes result in a longpress-action: Android Espresso performs longClick instead of click
I found a pretty good summary of reasons and fixes here: https://semaphoreci.com/community/tutorials/how-to-deal-with-and-eliminate-flaky-tests
I stumbled upon this thread cause we also struggeling with randomly failing tests, which seem to not have any of the mentioned reasons.
Upvotes: 4