-1
我已經在android中使用espresso和ui automation編寫了測試用例。現在,當我運行我的兩個不同類的測試用例時,它總是給出錯誤套件類不使用junit4在espresso中運行第二個測試類android
java.lang.RuntimeException:找不到活動。您是否忘記通過調用getActivity()或startActivitySync或類似方法來啓動該活動?
並且不運行MainActivity2Test
類。我無法理解我做錯了什麼。搜索有關此錯誤也沒有找到任何解決方案。請幫幫我。
AllTestsSuite.java
@RunWith(Suite.class)
@Suite.SuiteClasses ({
MainActivityTest.class,
MainActivity2Test.class,
})
public class AllTestsSuite {
}
MainActivity.java
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
UiDevice device;
@Rule
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule(MainActivity.class, true, false);
@Test
public void test1_doLogin(){
device = UiDevice.getInstance(getInstrumentation());
device.pressHome();
device.wait(hasObject(desc("Apps")), 3000);
UiObject2 appsButton = device.findObject(desc("Apps"));
appsButton.click();
UiObject2 appsButton1 = device.findObject(desc("MyApp"));
appsButton1.click();
test2_emaillPass();
}
@Test
public void test2_emaillPass(){
}
}
MainActivity2Test.java
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4.class)
public class MainActivity2Test {
UiDevice device;
@Rule
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule(MainActivity.class, true, false);
@Test
public void test3_productFamily(){
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
test4_Product();
}
@Test
public void test4_Product() {
device = UiDevice.getInstance(getInstrumentation());
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
device.wait(hasObject(By.text("First product")), 4000);
test5_Detail();
}
最後一個標誌更改爲TRUE,但仍然得到錯誤 –
通過使最後一個標誌爲true,應用程序越來越多刷新也times.And拋出空指針異常 –