java - Resources$NotFoundException when calling Robolectric.buildActivity() -


i using robolectric 3.0 rc3 unit testing in android studio. , getting resourcenotfoundexception every time run test. please me resolve issue.

build.gradle

dependencies {     testcompile 'junit:junit:4.12'     compile filetree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:appcompat-v7:22.0.0'     testcompile 'org.mockito:mockito-core:1.9.5'     testcompile 'org.robolectric:robolectric:3.0-rc3'     compile 'com.ibm.icu:icu4j:53.1' } 

test class

@before public void setup() throws exception {     activity = robolectric.buildactivity(mainactivity.class).create().get(); } @test public void pressingthebuttonshouldstartthelistactivity() throws exception {    //something test } 

so, whenever robolectric.buildactivity() resources$notfoundexception. resource #0x7f040016 points r.layout.activity_main(xml). following id stack trace-

android.content.res.resources$notfoundexception: unable find resource id #0x7f040016 @ org.robolectric.shadows.shadowresources.checkresname(shadowresources.java:343) @ org.robolectric.shadows.shadowresources.resolveresname(shadowresources.java:338) @ org.robolectric.shadows.shadowresources.loadxmlresourceparser(shadowresources.java:429) @ android.content.res.resources.loadxmlresourceparser(resources.java) @ android.content.res.resources.getlayout(resources.java:852) @ android.view.layoutinflater.inflate(layoutinflater.java:394) @ android.view.layoutinflater.inflate(layoutinflater.java:352) @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:256) @ android.app.activity.setcontentview(activity.java:1867) @ com.aricent.anas.unittesting2.mainactivity.oncreate(mainactivity.java:15) //****here**** @ android.app.activity.performcreate(activity.java:5008) @ org.robolectric.util.reflectionhelpers.callinstancemethod(reflectionhelpers.java:195) @ org.robolectric.util.activitycontroller$1.run(activitycontroller.java:122) @ org.robolectric.shadows.shadowlooper.runpaused(shadowlooper.java:305) @ org.robolectric.shadows.coreshadowsadapter$2.runpaused(coreshadowsadapter.java:45) @ org.robolectric.util.activitycontroller.create(activitycontroller.java:118) @ org.robolectric.util.activitycontroller.create(activitycontroller.java:129) @ com.aricent.anas.unittesting2.mainactivitytest.setup(mainactivitytest.java:32) //****here**** @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:24) @ org.robolectric.robolectrictestrunner$2.evaluate(robolectrictestrunner.java:245) @ org.robolectric.robolectrictestrunner.runchild(robolectrictestrunner.java:185) @ org.robolectric.robolectrictestrunner.runchild(robolectrictestrunner.java:54) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.robolectric.robolectrictestrunner$1.evaluate(robolectrictestrunner.java:149) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runner.junitcore.run(junitcore.java:137) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140)   process finished exit code -1 

mainactivity.java:15 setcontentview(r.layout.activity_main);

mainactivitytest.java:32 activity = robolectric.buildactivity(mainactivity.class).create().get();

is test class annotated correctly? , using correct path manifest file? following works me:

@runwith(robolectrictestrunner.class) @config(manifest = "src/main/androidmanifest.xml", emulatesdk = build.version_codes.lollipop) public class myactivitytest { .... } 

removing config annotation causes resourcesnotfound exception mentioned.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -