I want to write some automated test for one of my application. All of the functionality requires login.
So, i have written test, but for each test, it is doing login and testing the functionality. Is there anyway which will help me to login only once and then run all test?
Easiest way would be to write all test in only one test method. But i think it would be ugly way to achieve that. Any cleaner solution so, test will login only once and then run set of test.
Following is my test code:
@RunWith(AndroidJUnit4.class)
public class AllDisabledTest {
public static final String USER_NAME = "all_disabled";
public static final String DISPLAY_NAME = "All Disabled";
public static final String PASSWORD = "1234";
@Rule
public ActivityTestRule<LoginActivity> mActivityRule = new ActivityTestRule<>(
LoginActivity.class);
@Before
public void loginToApp(){
onView(withId(R.id.edit_email)).perform(replaceText(USER_NAME));
onView(withId(R.id.edit_password)).perform(replaceText(PASSWORD));
onView(withId(R.id.login_button)).perform(click());
}
@Test
public void checkIfFoodItemAddedToCart(){
onData(anything()).inAdapterView(withId(R.id.menu_item_grid)).atPosition(2).perform(click());
onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).onChildView(withId(R.id.item_name)).check(matches(withText("BLUEITEM")));
}
}
Thank you in advance :).