android.support.test.espresso.NoActivityResumedException:阶段RESUMED中没有活动 [英] android.support.test.espresso.NoActivityResumedException: No activities in stage RESUMED

查看:190
本文介绍了android.support.test.espresso.NoActivityResumedException:阶段RESUMED中没有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的活动编写测试用例.我有几种活动,当我尝试对其他ActivityTest类进行测试时遇到以下错误时,其中一项没有问题.

I'm trying to write test cases for my activities. I have several activities and there is no issue for one of them while I'm getting following error when I try to run tests over other ActivityTest classes.

android.support.test.espresso.NoActivityResumedException:否 恢复阶段的活动.您是否忘了发起活动. (test.getActivity()或类似名称)?

android.support.test.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?

这是我所有的测试用例都失败的班级:

This is my class that all my test cases fails:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class LocatingActivityTest
{
    @Rule
    public ActivityTestRule<LocatingActivity> mActivityTestRule = new ActivityTestRule<>(LocatingActivity.class);

    private LocatingActivity mLocatingActivity;

    @Before
    public void setup()
    {
        mLocatingActivity = mActivityTestRule.getActivity();
    }

    @Test
    public void viewsMustBeVisible()
    {
        onView(withId(R.id.locating_text)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.sonarView)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.locating_cancel_booking)).check(matches(isCompletelyDisplayed()));

        onView(withId(R.id.locating_list_view)).check(matches(isDisplayed()));
    }

    @Test
    public void viewsMustBeEnabled()
    {
        onView(withId(R.id.tvNoDriverFound)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.tvNextSearch)).check(matches(not(isCompletelyDisplayed())));
    }
}

但这是我所有测试用例都通过的另一个类:

However this is my another class that all of its test cases passes:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class BookingActivityTest
{
    @Rule
    public IntentsTestRule<BookingTaxiActivity> mActivityTestRule = new IntentsTestRule<>(BookingTaxiActivity.class);

    private BookingTaxiActivity mBookingTaxiActivity;

    @Before
    public void setup()
    {
        mBookingTaxiActivity = mActivityTestRule.getActivity();
    }

    @Test
    public void viewsMustBeVisible()
    {
        onView(withId(R.id.booking_pick_up_layout)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.booking_drop_off_layout)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.fab_booking)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.booking_estimated_fare)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.ibMenu)).check(matches(isCompletelyDisplayed()));
        onView(withId(R.id.booking_toolbar)).check(matches(isCompletelyDisplayed()));

        onView(withId(R.id.booking_taxi_type_picker)).check(matches(isDisplayed()));
    }

    @Test
    public void viewsMustBeEnabled()
    {
        // These Views are off the screen
        onView(withId(R.id.tag_widget)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.payment_btn)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.current_pickup_view)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.advance_pickup_view)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.booking_notes_btn)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.promo_code_btn)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.taxi_warning)).check(matches(not(isCompletelyDisplayed())));
        onView(withId(R.id.booking_book_now)).check(matches(not(isCompletelyDisplayed())));
    }
}

我不知道为什么上述类别的测试通过而其他类别的测试却失败.

I have no idea why tests of above class passes while other classes fails.

推荐答案

如果运行设备处于锁定模式和/或活动处于非活动状态,则会触发此错误.确保您的设备已打开并且应用程序/测试能够在前台运行! 有史以来最简单的修复程序(至少对我而言)!

If the run device is in lock mode, and/or activity inactive, will trigger this error. Make sure your device is on and app/test is able to run in foreground! The easiest fix ever(at least for me)!

这篇关于android.support.test.espresso.NoActivityResumedException:阶段RESUMED中没有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆