Skip to content Skip to sidebar Skip to footer

Espresso Not Starting Activity The Same For Second Iteration In Parameterised Test

Is there something different about how Espresso runs tests after the first one when using parameterised tests? I have two parameters and they both run just fine if I do them on the

Solution 1:

Ok I found a solution. Since onDestroy from the previous test is being called after onResume in the current test, I moved the code in onDestroy that clears my listeners to the start of onResume. Now when the other code in onResume runs it's not nullified by the bad timing of onDestroy. The listeners are accessed via the repository which stays active the whole time.

Hopefully this all makes sense to anyone reading in case they face a similar problem. So far I haven't noticed any side effects of this workaround. All the tests pass and the actual app works as well when running manually.

Edit: This workaround is now causing problems so I have to unaccept my answer. The reason is because when I call another Activity for result, when it comes back the listeners are killed in onResume. In this case onDestroy isn't killed yet so would not cause this problem.

Edit 2 and current solution: this question was a bit hard to test for readers so I created a test app and a new simpler question. I've since found a working solution that I've explained in this post: Espresso not waiting till Activity is destroyed, before creating a new one for the next test

I believe based on reading some Meta Q&A's that SO prefers that questions aren't deleted so I'll just leave this question here.

Post a Comment for "Espresso Not Starting Activity The Same For Second Iteration In Parameterised Test"