使用Espresso进行Android UI测试:阶段RESUMED中没有任何活动

时间:2014-10-24 16:44:09

标签: android listview testing ui-testing expresso

我目前正在努力在实现LoaderManager.LoaderCallbacks的Android ListActivity上实现功能测试。此Activity有一个简单的布局,其中包含一个EditText,供用户输入一些字符串; ListView,它通过Custom CursorAdapter填充,从自定义内容提供程序获取数据,并使用LoadManager自动更新列表视图内容它改变了。

此ListActivity的预期功能仅适用于用户在EditText上输入某些内容并从ListView中选择一个或多个项目。

为了实现这个功能测试,我正在使用Expresso,这是我的实现:

public class NewWordActivityFunctionalTest extends ActivityInstrumentationTestCase2<NewWordActivity>{

    public NewWordActivityFunctionalTest() {
        super(NewWordActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testFillNewThemeFormAndSubmit() throws InterruptedException {
        onView(withId(R.id.submit_new_word_button))
        .perform(click());
    }
}

如果我运行它,我得到的错误堆栈跟踪如下:

com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:69)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:159)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:90)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:73)
at pt.consipere.hangman.ui.test.NewWordActivityFunctionalTest.testFillNewThemeFormAndSubmit(NewWordActivityFunctionalTest.java:36)
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:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

此测试设置与我在我的应用程序的其他功能测试中使用的完全相同,这使我认为问题可能与测试初始化​​有关,因为其他测试的唯一区别是这个事实activity正在使用CursorAdapter和LoadManager。

如果有人需要更多情境化,请询问。 谢谢:))

0 个答案:

没有答案