3

次のシナリオをテストしようとしています。オートコンプリート テキストビューに文字を入力し、下にスクロールしてオプションの 1 つを選択し、ボタンをクリックすると、新しいアクティビティが開始されます。新しい活動が始まったかどうかを確認したい。これが試験方法です。

public void testSpinnerUI() {

    mActivity.runOnUiThread(new Runnable() {
        public void run() {

            mFromLocation.requestFocusFromTouch(); // use reqestFocusFromTouch() and not requestFocus()
        }
    });
    //set a busstop that has W in it, and scroll to the 4th position of the list - In this case Welcome
    this.sendKeys(KeyEvent.KEYCODE_W);
    try {
        Thread.sleep(2000); //wait for 2 seconds so that the autocomplete loads
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    for (int i = 1; i <= 4; i++) {
      this.sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    }

    this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

    assertEquals("Welcome", mFromLocation.getText().toString());

    //hit down arrow twice and centre button

    this.sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    this.sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

    this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

    assertEquals(com.myApp.RouteListActivity.class, getActivity());

}

テストは最後の assertEquals(com.myApp.RouteListActivity.class, getActivity()) で失敗します。新しいアクティビティが開始されたかどうかをテストする方法を教えてください。

4

1 に答える 1

3

ActivityManagerここで便利に示されているようにを使用する必要があります: https ://stackoverflow.com/questions/3908029/android-get-icons-of-running-activities

簡単な要約:

ActivityManager am = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> processes = am.getRecentTasks(5);

実行中のすべてのプロセスのリストを取得します(GET_TASKS権限が必要です)。そのリストからアクティビティを検索できます。これらのタスクの1つには、origActivityアクティビティと同じ名前のプロパティが必要です。

于 2011-05-10T06:54:37.697 に答える