3
我試圖測試以下情形,在自動完成textview中輸入一個字母,向下滾動並選擇其中一個選項,然後單擊一個按鈕,按鈕單擊開始一個新活動。我想檢查新活動是否已經開始。這是測試方法。Android - 測試是否有其他活動已開始
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())。你能指導我如何測試新活動是否已經開始?
嗨,我只是試過這個,我給測試項目的GET_TASKS權限,但我得到了異常說我沒有權限。如果我將權限移動到實際的應用程序,我正在測試它的工作。但那不是很理想。該應用程序不應該需要測試應該的權限。這是正常的嗎?難道我做錯了什麼? – Kurt 2012-07-09 09:28:09