Android的测试启动另一个应用程序的活动 [英] Android test for Launching activity of Another app
本文介绍了Android的测试启动另一个应用程序的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我有一个列表视图,显示系统中的所有当前已安装的应用程序。点击一个项目将选择下一个活动(已安装的应用程序之一)推出。
我想添加一个活动测试,用于测试这种情况的发生。我有一个可扩展的列表视图,保存安装的应用程序列表。
//获得我们要启动的列表项的子视图
最终的视图V = mExpListData.getChildView(0,launched_app_pos,假的,NULL,NULL);
assertNotNull(子列表视图空,V);
mActivity.runOnUiThread(
新的Runnable(){
公共无效的run(){
//点击并推出神庙逃亡
mExpList.requestFocus();
}
}
);
。getInstrumentation()waitForIdleSync();
TextView的标题=(TextView中)诉。
findViewById(com.example.demo.R.id.apkname);
assertNotNull(标题空,标题);
的assertEquals(程序名称不正确,愤怒的小鸟,title.getText());
最终诠释view_pos = 9;
mActivity.runOnUiThread(
新的Runnable(){
公共无效的run(){
//点击并推出神庙逃亡
mExpList.performItemClick(ⅴ,view_pos,view_pos);
} // run()方法的定义结束
匿名Runnable对象实例化} //结束
); // runOnUiThread的调用结束
。getInstrumentation()waitForIdleSync();
意图launchIntent =
。mActivity.getPackageManager()getLaunchIntentForPackage(selectedApp.getPackageName());
//如何我添加了一个活动监控器,将等待该活动将启动
任何想法?
我已经加入这个作为建议如下 - 仍然不起作用
launchIntent.setAction(Intent.ACTION_MAIN);
最后的IntentFilter的IntentFilter =新的IntentFilter();
intentFilter.addAction(Intent.ACTION_MAIN);
活动监视器mAppActivityMonitor =新活动监视器(IntentFilter的,空,假);
mAppActivityMonitor.waitForActivityWithTimeout(超时);
的assertEquals(1,mAppActivityMonitor.getHits());
解决方案
您没有设置行动电话intent.setAction(android.intent.action.MAIN);
In my App, I have a list view that shows all the currently installed apps in the system. Clicking on an item will select the next activity (one of the installed apps) to be launched.
I am trying to add a Activity Test for testing that this happens. I have an expandable list view that holds the list of installed apps.
// 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
Any ideas?
I have added this as suggested below - still doesnt work
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());
解决方案
You didn't set the action call intent.setAction(android.intent.action.MAIN);
这篇关于Android的测试启动另一个应用程序的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文