現在、LoaderManager.LoaderCallbacks を実装する Android ListActivity に機能テストを実装するのに苦労しています。このアクティビティには、ユーザーが文字列を入力するための EditText と、カスタム コンテンツ プロバイダーからデータをフェッチするカスタム CursorAdapter を介して入力される ListView を含むシンプルなレイアウトがあり、LoadManager を使用して、次の場合にリスト ビューのコンテンツを自動的に更新します。それは変わる。
この ListActivity の期待される機能は、ユーザーが EditText に文字列を入力し、ListView から 1 つまたは複数の項目を選択することだけです。
この機能テストを達成するために、私は 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)
このテスト設定は、アプリの他の機能テストで使用したものと同じで、完全に正常に機能しました。他のテストの唯一の違いは、このアクティビティがCursorAdapter と LoadManager。
誰かがより文脈化が必要な場合は、尋ねてください。ありがとうございました :)