Hi there, I've been trying to get robolectric tests running with 3.0-rc2 and having no luck so far.
I used to be able to build robolectric tests just fine when I was using `androidTestCompile('org.robolectric:robolectric:3.0-SNAPSHOT')`
However, I am seeing these errors every time I try to tun the tests
java.lang.RuntimeException: android.content.res.Resources$NotFoundException: unknown resource 2131165228
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:228)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: android.content.res.Resources$NotFoundException: unknown resource 2131165228
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:332)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:70)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:270)
at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:361)
at android.content.res.Resources.getText(Resources.java)
at android.content.res.Resources.getString(Resources.java:360)
at org.robolectric.shadows.ShadowContext.getString(ShadowContext.java:39)
at org.robolectric.shadows.ShadowContextWrapper.getString(ShadowContextWrapper.java:69)
at android.content.Context.getString(Context.java)
at com.themis.clioAndroid.authentication.AccountUtils.getAccounts(AccountUtils.java:85)
at com.themis.clioAndroid.authentication.AccountUtils.isAccountAvailable(AccountUtils.java:50)
at com.themis.clioAndroid.testhelper.TestApplicationModule.provideAccountUtils(TestApplicationModule.java:33)
at com.themis.clioAndroid.testhelper.TestApplicationModule$$ModuleAdapter$ProvideAccountUtilsProvidesAdapter.get(TestApplicationModule$$ModuleAdapter.java:62)
at com.themis.clioAndroid.testhelper.TestApplicationModule$$ModuleAdapter$ProvideAccountUtilsProvidesAdapter.get(TestApplicationModule$$ModuleAdapter.java:46)
at dagger.internal.Linker$SingletonBinding.get(Linker.java:364)
at com.themis.clioAndroid.ClioAppLifecycleHandler$$InjectAdapter.injectMembers(ClioAppLifecycleHandler$$InjectAdapter.java:74)
at com.themis.clioAndroid.ClioAppLifecycleHandler$$InjectAdapter.get(ClioAppLifecycleHandler$$InjectAdapter.java:63)
at com.themis.clioAndroid.ClioAppLifecycleHandler$$InjectAdapter.get(ClioAppLifecycleHandler$$InjectAdapter.java:23)
at dagger.internal.loaders.ReflectiveAtInjectBinding.injectMembers(ReflectiveAtInjectBinding.java:120)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:281)
at com.themis.clioAndroid.ClioApp.inject(ClioApp.java:119)
at com.themis.clioAndroid.ClioApp.onCreate(ClioApp.java:58)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:131)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:431)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:224)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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 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)
... 7 more
I am losing ideas on why I can no longer build Robolectric tests.
Here is my build.gradle with relevant to Robolectric.
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'org.robolectric:robolectric-gradle-plugin:0.14.+'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
apply plugin: 'robolectric'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services-base:6.5.+'
compile "com.android.support:appcompat-v7:21.0.3"
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger'
exclude group: 'com.google.guava'
}
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:3.0-rc2') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
androidTestCompile('org.robolectric:shadows-support-v4:3.0-rc1') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
androidTestProvided('org.mockito:mockito-all:1.9.5')
}
robolectric {
// configure the set of classes for JUnit tests
include '**/*Test.class'
exclude '**/espresso/**/*.class'
// configure max heap size of the test JVM
maxHeapSize = '2048m'
// configure the test JVM arguments
jvmArgs '-XX:MaxPermSize=512m', '-XX:-UseSplitVerifier'
// Specify max number of processes (default is 1)
// set environment variable MAX_PARALLEL_FORKS=true
maxParallelForks = System.getenv("MAX_PARALLEL_FORKS") ? 4 : 2
// Specify max number of test classes to execute in a test process
// before restarting the process (default is unlimited)
forkEvery = 150
// configure whether failing tests should fail the build
ignoreFailures true
// use afterTest to listen to the test execution results
afterTest { descriptor, result ->
println "Executing test for ${descriptor.name} with result: ${result.resultType}"
}
}
And in the tests, I have the following test runner.
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
Do you see any reasons why I am getting ResourcesNotFoundException?
FYI: it happens even after deleted caches from `~/.m2` and `~/.gradle/caches/`.
any suggestions are welcome.
cheers