Home » Android » Android Espresso: How to create test-suite with several activities?

Android Espresso: How to create test-suite with several activities?

Posted by: admin November 1, 2017 Leave a comment


I have just started studying Espresso tests, but I have searched throw StackOverFlow topics and couldn’t found solution for my needs.

Prehistory of my question:

I have android application with lots of activities. Generally separate UI tests were created for different flows of the app (each flow require separate activity, so that’s why I have implemented tests in a different classes).
In my case background and UI usync occurs, that’s why I can’t start from first activity and keep going to the next and next.
The only solution which I have found and it really work with current app – is using of idling resources for app activities.

SO now am trying to understand how can I put all these separate classes (each class use own rules and activities for these rules) to the functional suite??

My experience:

1) Positive – using idling resource which require changes in developer’s source code, but there is still only one activity in suite:



public class ForSeveralActs {
public final ActivityTestRule<TargetedActivity> mTargetedActivityRule = new ActivityTestRule<>(TargetedActivity.class, true, true);

final String username = "[email protected]";
final String password = "12345678";
private IdlingResource mIdlingRecourse;

public void setIdleResource() {
    mIdlingRecourse = mTargetedActivityRule.getActivity().getIdlingResource();

public void PassPermission_and_goto_MainActivity() {

    // First activity - LoginActivity



  // Here is elements of second activity - MainActivity, without idling methods I can't reach this element


public void unregisteredIdlingResource() {
    if (mIdlingRecourse != null) {

So in this example I have several tests and the last one will be performed on the next activity.

2) Negative – I have tried to launch all my tests (classes) though JUnit test-suite, so I just put all my classes (which also includes RULES for tests and ACTIVITIES) to the Junit suite (this scenario doesn’t work at all):


public class ESP_start {}

Here is the same question which I posted above:
How can I create suite from separate tests which are using different activities and rules, how it should look like?