Android Studio 单元测试 - 缺少 android.net.Uri

标签 android unit-testing

我无法在我的本地单元测试中使用 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/

相关文章:

Android - 绑定(bind)(观察)对象属性的 MVVM 架构

android - 是否可以在 Eclipse Android Gui 构建器中显示按钮状态?

Android:在 ImageView 中的图像上显示图像

android - 更改 ListView 或回收 View 的单个项目的布局

java - AssertThrows 在通过 Java Streams 时不抛出异常

unit-testing - Grails项目设置和约定-测试不是真正服务的spring组件

android - 在sqlite db中获取id和存储值的最大值

typescript - 如何使用 ts-mockito 模拟一个方法?

ruby - Rspec ruby 模拟

unit-testing - Grails测试中的模拟配置