【发布时间】:2020-11-28 06:01:52
【问题描述】:
我的活动类中有以下代码:
@Override
public boolean onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(getExternalFilesDir(null)).getAbsolutePath();
intent.setDataAndType(uri, "resource/folder");
if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
{
// case 1: another app exists
startActivity(intent);
}
else
{
// case 2: no app, so open dialog
DialogFragment dialog = new MyDialogFragment();
dialog.show(this.getSupportFragmentManager(), "tag");
}
return true;
}
在我的 Espresso 测试中,如何在同一台设备上测试这两种情况(无需卸载/重新安装其他应用)? 我查看了 Espresso Intents 和 Mockito,但还没有找到方法。
【问题讨论】:
-
// case 1: another app exists是什么意思?什么是另一个应用程序,没有应用程序和有应用程序有什么区别? -
案例1:在设备上发现了一个“文件浏览器”应用,我们将其打开。案例2:设备上没有找到文件资源管理器,所以我们显示一个对话框要求用户安装文件资源管理器
标签: android android-intent mocking mockito android-espresso