我无法在我的本地单元测试中使用 android.net.Uri(在开发机器上的 Android Studio 中运行)。我知道这是因为单元测试是针对“瘦”android.jar 执行的,带有仅抛出异常的 stub ,但这使得真正不可能测试任何与资源相关的内容(文件、URL 等)。
我在测试使用 json 的代码时遇到了同样的问题,为了解决它,我在我的 build.gradle 中添加了一个依赖项:
testCompile 'org.json:json:20140107'
android.net.Uri 有类似的解决方案吗?
最佳答案
找到解决方案 - https://github.com/bjoernQ/unmock-plugin .
我猜连谷歌都知道这个问题并推荐相同的解决方案 - https://code.google.com/p/android/issues/detail?id=145068 .
关于Android Studio 单元测试 - 缺少 android.net.Uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31904972/