浓缩咖啡测试:如何控制意图的内容



我的活动类中有以下代码:

@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意式咖啡和Mockito,但没有找到方法。

因为这里有这行代码:intent.resolveActivityInfo(getPackageManager((,0(

在运行测试之前,您可以尝试以编程方式将其设置为不为null。

最新更新