0
在我的應用程序中,我有一個列表視圖,顯示系統中當前安裝的所有應用程序。點擊一個項目將選擇下一個活動(已安裝的應用程序之一)以啓動。Android測試啓動另一個應用程序的活動
我想添加一個活動測試來測試這種情況。我有一個可擴展的列表視圖,其中包含已安裝應用程序的列表。
// Get the child view of the list item that we want to launch
final View v = mExpListData.getChildView(0, launched_app_pos, false, null, null);
assertNotNull("Child List View Null", v);
mActivity.runOnUiThread(
new Runnable() {
public void run() {
// Click and launch temple run
mExpList.requestFocus();
}
}
);
getInstrumentation().waitForIdleSync();
TextView title = (TextView)v.
findViewById(com.example.demo.R.id.apkname);
assertNotNull("Title null", title);
assertEquals("App Name not correct", "Angry Birds", title.getText());
final int view_pos = 9;
mActivity.runOnUiThread(
new Runnable() {
public void run() {
// Click and launch temple run
mExpList.performItemClick(v, view_pos, view_pos);
} // end of run() method definition
} // end of anonymous Runnable object instantiation
); // end of invocation of runOnUiThread
getInstrumentation().waitForIdleSync();
Intent launchIntent =
mActivity.getPackageManager().getLaunchIntentForPackage(selectedApp.getPackageName());
// HOW TO I ADD A ACTIVITY MONITOR THAT WILL WAIT FOR THE ACTIVITY TO BE LAUNCHED
任何想法?
的建議下面我加入了這一點 - 仍然不起作用
launchIntent.setAction(Intent.ACTION_MAIN);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_MAIN);
ActivityMonitor mAppActivityMonitor = new ActivityMonitor(intentFilter, null, false);
mAppActivityMonitor.waitForActivityWithTimeout(TIMEOUT);
assertEquals(1, mAppActivityMonitor.getHits());
編輯帖子並添加你的建議。這是你指的是什麼? –