我正在尝试为我的活动编写测试用例。我有几项活动,其中一项活动没有问题,而当我尝试对其他ActivityTest
类运行测试时出现以下错误。
android.support.test.espresso.NoActivityResumedException:RESUMED阶段没有活动。您是否忘记启动活动。(test.getActivity() 或类似的)?
这是我的所有测试用例都失败的课程:
@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())));
}
}
然而,这是我的另一个类,它的所有测试用例都通过了:
@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())));
}
}
我不知道为什么上述类的测试通过而其他类失败。