android - Library resources with Robolectric 3 - JodaTime -
getting resourcenotfoundexception when using library robolectic 3.0-rc3. resource declared in build.gradle compile 'net.danlew:android.joda:2.8.0'. android port of joda-time.
android.content.res.resources$notfoundexception: unable find resource id #0x7f0501da @ org.robolectric.shadows.shadowresources.checkresname(shadowresources.java:343) @ org.robolectric.shadows.shadowresources.getresname(shadowresources.java:333) @ org.robolectric.shadows.shadowresources.openrawresource(shadowresources.java:382) @ android.content.res.resources.openrawresource(resources.java) @ net.danlew.android.joda.resourcezoneinfoprovider.openresource(resourcezoneinfoprovider.java:120) @ net.danlew.android.joda.resourcezoneinfoprovider.<init>(resourcezoneinfoprovider.java:39)
application class:
@override public void oncreate() { super.oncreate(); jodatime.init(this); }
my test class:
@runwith(robolectricgradletestrunner.class) @config(constants = buildconfig.class, sdk = 21) public class mytest { @before public void setup() { } @test public void mytest() { //test stuff }
}
you need initialise library in tests, robolectric runtime environment. add setup()
methods.
jodatimeandroid.init(runtimeenvironment.application);
so test this:
@runwith(robolectricgradletestrunner.class) @config(constants = buildconfig.class, sdk = 21) public class myapplicationtest { @before public void setup() { jodatimeandroid.init(runtimeenvironment.application); } @test public void mytest() { //test stuff datetime adatetime = new datetime(); datetime bdatetime = new datetime(adatetime); assertequals(adatetime, bdatetime); } }
Comments
Post a Comment