【发布时间】:2013-12-09 11:43:05
【问题描述】:
在我的应用程序中,我有一个列表视图,显示系统中当前安装的所有应用程序。点击一个项目将选择下一个要启动的活动(已安装的应用之一)。
我正在尝试添加一个活动测试来测试是否会发生这种情况。我有一个可展开的列表视图,其中包含已安装应用程序的列表。
// 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());
【问题讨论】:
标签: android unit-testing functional-testing