使Intent.resolveActivity()在Roboletric测试中返回true

时间:2018-02-04 18:10:46

标签: android android-testing robolectric

我无法找到让robolectric解析活动的方法。我需要测试以下代码并模拟resolveActivity以返回true。

# puts "[$lib configure hardHdlDir]/[$file configure relativePathname]"

1 个答案:

答案 0 :(得分:0)

在现实生活中,resolveActivity的结果实际上取决于应用程序中的内容以及设备中的应用程序。所以我们所能做的就是配置Robolectric,以便在单元测试中涵盖代码路径(resolveActivity == null或nor)。

我们使用ShadowPackageManager配置Intent.resolveActivity返回的内容。有关详细信息,请参阅Add resolve info to Robolectric package manager。请注意,Robolectric 3.x和2.x具有不同的代码样式。