Android
上使用Mockito
+Dexmaker
,测试用例运行时,报告错误:
1 2 3 4 5 6 7 |
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"
,如下:
1 2 3 4 5 6 7 8 9 10 |
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()); } } |