Android上使用Mockito+Dexmaker报告错误“java.lang.IllegalArgumentException: dexcache == null (and no default could be found; consider setting the 'dexmaker.dexcache' system property) ”

Android上使用Mockito+Dexmaker,测试用例运行时,报告错误:

java.lang.IllegalArgumentException: 
    dexcache == null (and no default could be found; 
    consider setting the 'dexmaker.dexcache' system property)
at com.google.dexmaker.DexMaker.generateAndLoad(DexMaker.java:359)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:252)
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:54)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)

解决方法就是在调用Mockito之前设置环境变量"dexmaker.dexcache",如下:

public class BasicTestCase extends AndroidTestCase {
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        /*解决BUG dexcache == null (and no default could be found; consider setting the 'dexmaker.dexcache' system pr*/
        System.setProperty(
                "dexmaker.dexcache",
                getContext().getCacheDir().getPath());
    }
}

参考链接


Mockito + Dexmaker on Android

发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注