Robotium を使用してアプリケーション機能をテストしようとしています。機能の 1 つは、最初のアクティビティがアクティビティ スタックの最上位のビューから起動されたときに、スタックの最上位をクリアし、既存の Activity ig("MainActivity") を再利用する必要があることです。
フロー:
FirstScreen -> LoginActivityScreen -> RegistrationScreen -> FirstScreen
解決策は非常に簡単です。
Intent intent = new Intent(getBaseContext(), FirstScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
フラグIntent.FLAG_ACTIVITY_CLEAR_TOPを設定すると、FirstScreenがアプリケーション スタックの一番上に戻ります。
私が書こうとしているテストは、ハードウェアの [戻る] ボタンが押されたときにアプリが消え、ネイティブのホーム (ランチャー)アプリケーションが現在のアクティビティであることを確認することです。
マイ インストルメンテーション テストケース:
@Smoke
public void testshouldBeOnLauncherHomeScreen() {
// Monitor the Home (Launcher) Activity being Launched
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MAIN");
filter.addCategory("android.intent.category.HOME");
ActivityMonitor monitor = getInstrumentation().addMonitor(filter, null, false);
// go back to the launcher home
robotium.goBack();
assertEquals(1, monitor.getHits());
}
Launcher アプリのアクティビティが現在のアクティビティであると断言したいと思います。アイデアや提案は大歓迎です。