I have been sucessfully using this code to load resources both in an app and its unit tests with Robolectric 2.4:
getContext().getResources().getIdentifier(resName, "string", getContext().getPackageName());
where Context would be MyApplication in the App and TestMyApplication in Robolectric tests.
With Robolectric 3.0 this no longer works when an applicationIdSuffix is added to the build file, the call returns 0.
Is this a known issue? This is on com.android.tools.build:gradle:1.2.0-beta1 and org.robolectric:robolectric:3.0-rc2
Update https://github.com/robolectric/robolectric/issues/1623
There is actually a simple fix for this now, just add @Config(constants = BuildConfig.class, packageName = com.your.package)
See https://github.com/robolectric/robolectric-samples/tree/master/android-flavors
As workaround I created another build flavour jenkins
where I removed suffix editing. Unfortunately it is not proper solution if you want to test something specific/customised for flavour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With