electricspock
electricspock copied to clipboard
module resources issue in 0.5.0.1
Hello. I switched to ElectricSpecification from RopoSpecification(Robospock) since i have robolectric 3.3.1 and your impl seems to be working with this robolectric version. I will note that i have a robolectric working in modules of application.
It basically setup but i have problem accessing resources i have basically such test that is in module (not app)
@Config(manifest='src/main/AndroidManifest.xml') class ExampleRoboSpec extends ElectricSpecification { } now whatever i put to manifest config i still get issue/warning:
WARNING: No manifest file found at ./AndroidManifest.xml. Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE).
what finally ends up with: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f060080 in packages [android, org.robolectric.default]
It seems that @Config annotation (org.robolectric.annotation.Config) is not respected at all. I have also a default working robolectric with robolectric.properties file but this is also not used
Question is how to get it working in general (module or app) since i tried both with still same above warning and resources missing
Can I ask why did you closed the issue?
It was a mistake. Reopened.
The issues involves 2 parts.
Config
annotation
Unfortunately, you are right that the library does not honour the Config
annotation of ElectricSpecification
and it will be fixed soon, stay tune.
Default location of AndroidManifest.xml
Robolectric looks for AndroidManifest.xml
at src/main/AndroidManifest.xml
, or the location specified in build.gradle. So it should work out of the box if your working directory of test run is the module directory of the project. You don't need @Config
at all if the XML file is in default location. If you want AndroidManifest.xml
to be in custom location, please wait for a fix mentioned above.
Changing working directory in Android Studio
If you are using Android Studio and run your test class directly, the configuration created by Android Studio does not specify working directory. Default working directory would be the project base directory. That's bad for our purpose.
To make things work, one shall set the working directory to your module directory. For example, if your Android is at /home/hkhc/myproject
, and your module is named app
. Then the working directory should be /home/hkhc/myproject/app
.
If you have run your test class before, you may change the working directory by the following steps:
- Click the "Select Run/Debug configuration" box in toolbar.
- Click "Edit configurations..."
- Select the test class at left hand side
- Enter your module directory at "Working directory" box, or you may just click the option button at the right hand side of the box and select "MODULE_DIR"
- Click "OK"
Then run the test again.
Just to clarify.
I started to work with @Config since setup was not working with ElectricSpock.
Will add also that robolectric is working in every module of my application based on @RunWith(RobolectricTestRunner.class)
and
robolectric.properties file stored in {module}/src/test/resources/ directory
which looks like this:
sdk=21
constants=myapp.BuildConfig
application=myapp.TestApplication
So it seems that source of my issue is that robolectric started with ElectricSpock is not configured based on this file.
After further investigation it seems that when in android studio i use home directory as {module}/src/main the problem does not occur. The problem still exists when using gradlew commandline to build since there module working directory stays default
Further tracking point out also that robolectric.properties file is also not used the same as @config annotation.
ok. sorry for the inconvenience. After some digging when i put the file robolectric.properties directly to {module}/src/test/resources
it works properly
previously i had this file in resources deeper prefixed with my package name so like: {module}/src/test/resources/mypackage/
this was NOT working
Now it is up to you what to do with @Config. The source of the issue do not exist in ElectricSpock in my opinion or can be configured as i realized.
Version 0.6 should work with @config properly.