简体   繁体   中英

Espresso android testing

How do I start my test in a specific activity? Say I'm testing a favorites tab in my app, but I'd like my test to start on the login screen, what method would I use to do that? I can't find anything about it anywhere and I'm sure it's just a simple call.

Idly you should test a single activity in the instrumentation tests. If you wish to test the whole flow then go for automation testing using calabash . In instrumentation test you can test a single activity with different datasets and it will be much faster.

Still if you want to test the whole flow in instrumentation then you can provide the activity in the ActivityTestRule .

You have to provide the activity you want to launch first into ActivityTestRule, then login, navigate to the Favorites and tests it:

@RunWith(AndroidJUnit4.class)
public class TestFavorites {

    @Rule
    public ActivityTestRule<LoginActivity> mActivityRule = new ActivityTestRule(LoginActivity.class);

    @Before
    public void setUp() {
        //your setUp
    }

    @Test
    public void testSaveOtherContactToPhoneContacts() {
        logInUser(); //do the login
        //navigate to the favorites tab and test it
    }

    @After
    public void tearDown() {
        //your tearDown
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM