我正在使用 Robotium 对 Android 应用程序进行功能测试。我想在调用 onDestroy 后测试 onResume 行为。 这篇文章提示使用 Instrumentation,但我无法让它工作。我包括了以下内容,但这失败并出现 IllegalStateException。是否可以销毁应用程序并重新启动它?
public class MainActivityFunctionalTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public MainActivityFunctionalTest() {
super(MainActivity.class);
}
public void testActionList() {
getInstrumentation().callActivityOnDestroy(solo.getCurrentActivity());
...
}
导致以下异常:
java.lang.IllegalStateException: Must be called from main thread of process at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1373) at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1825) at android.app.Activity.performDestroy(Activity.java:5171) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1109) at nl.handypages.trviewer.test.MainActivityFunctionalTest.testActionList(MainActivityFunctionalTest.java:81) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)