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/

相关文章:

java - JAIN SIP 481 对 BYE 消息的响应

使用现有网站进行 Android 应用程序身份验证

unit-testing - 在 Go-kit 中为 make 处理函数编写单元测试

java - Easy mock 无法识别模拟服务

java - 错误 : class, 接口(interface),或预期枚举 - Android Studio

android - 从图库中的选定图像中获取图像的确切文件大小

python - 自动化测试平台,Matlab 还是 Python?

c# - 为什么以下测试使用 Mbunit 和 Rhino 模拟失败?

android - 连接 Wifi 时收到两次 CONNECTIVITY_ACTION Intent

c# - 在回调模拟设置中设置 ManualResetEvent 时出错