getActivity() call causes RuntimeException: Could not launch intent Intent act=android.intent.action.MAIN

前端 未结 4 1155
走了就别回头了
走了就别回头了 2021-02-05 15:47

Updated #1: more info added to the end of this post

I\'m new to Android development and testing.

I have three Espresso tests. First test passes, but the

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 15:57

    I found a workaround. I added code that hits back button multiple times in the tearDown() method to close all previously opened activities. Unfortunately I didn't found another method how to close all opened activities in Espresso. Robotium has a very convenient method for that purpose solo.finishOpenedActivities().

    public void tearDown() throws Exception {
        Log.d(TAG, "TEARDOWN");
    
        goBackN();
    
        super.tearDown();
    }
    
    private void goBackN() {
        final int N = 10; // how many times to hit back button
        try {
            for (int i = 0; i < N; i++)
                Espresso.pressBack();
        } catch (com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException e) {
            Log.e(TAG, "Closed all activities", e);
        }
    }
    

提交回复
热议问题