Espresso - How can I check if an activity is launched after performing a certain action?

后端 未结 8 1535
北海茫月
北海茫月 2020-12-02 15:34

the following is one of my Espresso test cases.

    public void testLoginAttempt() {
        Espresso.onView(ViewMatchers.withId(R.id.username)).perform(View         


        
8条回答
  •  伪装坚强ぢ
    2020-12-02 15:55

    You can use:

    intended(hasComponent(YourExpectedActivity.class.getName()));
    

    Requires this gradle entry:

    androidTestCompile ("com.android.support.test.espresso:espresso-intents:$espressoVersion")
    

    The import for the intended() and hasComponent()

    import static android.support.test.espresso.intent.Intents.intended;
    import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
    

    as mentioned by Shubam Gupta please remember to call Intents.init() before calling intended(). You can eventually call it in the @Before method.

提交回复
热议问题