用于启动另一个应用程序活动的Android测试
在我的应用程序中,我有一个列表视图,显示系统中当前安装的所有应用程序。单击项目将选择要启动的下一个活动(已安装的应用之一) 我试图添加一个活动测试来测试这种情况是否发生。我有一个可扩展的列表视图,其中包含已安装应用程序的列表用于启动另一个应用程序活动的Android测试,android,unit-testing,functional-testing,Android,Unit Testing,Functional Testing,在我的应用程序中,我有一个列表视图,显示系统中当前安装的所有应用程序。单击项目将选择要启动的下一个活动(已安装的应用之一) 我试图添加一个活动测试来测试这种情况是否发生。我有一个可扩展的列表视图,其中包含已安装应用程序的列表 // Get the child view of the list item that we want to launch final View v = mExpListData.getChildView(0, launched_app_pos, false, null,
// 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());
您没有设置操作调用intent.setAction(android.intent.action.MAIN) 编辑了帖子并添加了您的建议。这就是你所指的吗?