dimanche 22 octobre 2017

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

I have searched throw StackOverFlow topics, but couldn't found solution for my needs. Generally I have created separate UI tests for app flow, however these tests using different activities, I can't understand how to put all these separate tests in one test-suite, case they are using different activities.

For now I have next experience: 1) Positive exp with idling resource which require changes in developer's source code, but there is still only one activity in suite


@RunWith(AndroidJUnit4.class)

@LargeTest

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

final String username = "test@mail.com";
final String password = "12345678";
private IdlingResource mIdlingRecourse;

@Before
public void setIdleResource() {
    mIdlingRecourse = mTargetedActivityRule.getActivity().getIdlingResource();
    Espresso.registerIdlingResources(mIdlingRecourse);
}

@Test
public void PassPermission_and_goto_MainActivity() {

    // First activity - LoginActivity
    Espresso.onView(withId(R.id.activity_login_et_login))
            .perform(ViewActions.typeText(username));

    Espresso.onView(withId(R.id.activity_login_et_password))
            .perform(ViewActions.typeText(password))
            .perform(closeSoftKeyboard());

    Espresso.onView(withId(R.id.activity_login_btn_login))
            .check(matches(isDisplayed()))
            .check(matches(isClickable()))
            .perform(ViewActions.click());

    // Second activity - MainActivity
    Espresso.onView(withId(R.id.activity_updated_user_agreement_check_box_accept_terms))
            .perform(ViewActions.click());

    Espresso.onView(withId(R.id.activity_updated_user_agreement_button_accept))
            .perform(ViewActions.click());*/

    Espresso.onView(withId(R.id.helpMeCard_title))
            .check(matches(withText("help_me")));

}

@After
public void unregisteredIdlingResource() {
    if (mIdlingRecourse != null) {
        Espresso.unregisterIdlingResources(mIdlingRecourse);
    }
}


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

2) Negative exp, I have tried to launch all tests though JUnit test-suite:

@RunWith(Suite.class)
@Suite.SuiteClasses(
    {
            ESP_test1.class,
            ESP_test2.class,
            ESP_test3.class
    })

public class ESP_start {}

How can I create suite from separate tests which are using different activities and rules, how it should look like?

Aucun commentaire:

Enregistrer un commentaire