CI环境中的Robolectric

时间:2015-06-19 16:48:57

标签: android robolectric android-testing circleci

我遇到了一个问题,我的robolectric测试通过我的终端传递: ./gradlew test 和使用circleci上的所有工具正确配置的相同命令给出了这个错误:

java.lang.RuntimeException: java.lang.IllegalArgumentException: maxSize <= 0
        at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:238)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:185)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:149)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
        at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
        at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
        at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)      
        at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: maxSize <= 0
        at com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache.<init>(LruMemoryCache.java:33)
        at com.nostra13.universalimageloader.core.DefaultConfigurationFactory.createMemoryCache(DefaultConfigurationFactory.java:114)
        at com.nostra13.universalimageloader.core.ImageLoaderConfiguration$Builder.initEmptyFieldsWithDefaultValues(ImageLoaderConfiguration.java:584)
        at com.nostra13.universalimageloader.core.ImageLoaderConfiguration$Builder.build(ImageLoaderConfiguration.java:559)
        at com.heetch.HeetchApp.initImageLoader(HeetchApp.java:123)
        at com.heetch.HeetchApp.onCreate(HeetchApp.java:55)
        at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140)
        at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421)
        at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
        ... 34 more

我使用的是robolectric 3.0-rc3,我相信这个bug来自robolectric本身,但我没有任何线索可以找到解决此错误的地方。

1 个答案:

答案 0 :(得分:2)

解决方案是向ImageLoader添加内存缓存,如下所示:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .memoryCache(new WeakMemoryCache())
                .build();