Espresso を使い始めたばかりですが、その前に Robotium を試しました。LoginActivity をテストする必要があります。ロジックは次のとおりです。
- ユーザーは正しい資格情報を入力します。
- ユーザーには「Logging in..」という文字列が表示されます。
- ユーザーは文字列が消えるのを待ちます。
- ユーザーが MainActivity にあり、「ログインしています」と表示される
testLogin ソース:
public void testLogin() throws Exception{
onView(withId(R.id.login_email)).perform(typeText(LOGIN_EMAIL));
onView(withId(R.id.login_password)).perform(typeText(LOGIN_PASSWORD));
onView(withId(R.id.login_loginBtn)).perform(click());
onView(withText(R.string.loading_logging_in)).check(matches(isDisplayed()));
onView(withText("You're logged in")).check(matches(isDisplayed()));
}
問題は、エスプレッソが「ログインしています」という文字列が表示されるのを待たず、ログがまだ処理中に文字列を見つけようとしていたことでした。
ログキャット:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "You're logged in"
Thread.sleep(10000) を使用してみましたが、Thread.sleep(10000) で実行が終了し、エラーが発生します。
テストを完了できませんでした。理由: 「プロセスがクラッシュしたため、インストルメンテーションの実行に失敗しました。」詳細については、デバイスの logcat を確認してください。
ログキャット:
@@@ @@@ @@@殺されました cancelService in HttpReRegistrationService
その前に、waitForActivity(MainActivity.class) メソッドを使用しました。これを機能させるための回避策はありますか?