【发布时间】:2016-03-13 13:34:40
【问题描述】:
尝试使用 Robolectric 构建 android 单元测试。每次我需要模拟一个属于我的项目的方法时,创建一个 Shadow 类都会变得有点繁重。我认为在这种情况下使用 Mockito 会更容易和更轻松。
但是当我尝试使用 Mockito 方法时,我得到一个错误 java.lang.IllegalArgumentException: dexcache == null(并且找不到默认值;考虑设置“dexmaker.dexcache”系统属性)
为了解决这个问题,我认为需要通过调用来设置 dexcache 属性
System.setProperty("dexmaker.dexcache",getInstrumentation().getTargetContext().getCacheDir().getPath());
但我不知道在 Robolectric 中是否可以调用 getInstrumentation。请建议一种推荐的方法来模拟我在 Robolectric 中的项目的方法。
【问题讨论】:
标签: android unit-testing mockito robolectric