Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module resources issue in 0.5.0.1 #2

Open
clydzik opened this issue Jul 19, 2017 · 7 comments
Open

module resources issue in 0.5.0.1 #2

clydzik opened this issue Jul 19, 2017 · 7 comments

Comments

@clydzik
Copy link

clydzik commented Jul 19, 2017

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

@clydzik
Copy link
Author

clydzik commented Jul 19, 2017

Can I ask why did you closed the issue?

@hkhc hkhc reopened this Jul 19, 2017
@hkhc
Copy link
Owner

hkhc commented Jul 19, 2017

It was a mistake. Reopened.

@hkhc
Copy link
Owner

hkhc commented Jul 19, 2017

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:

  1. Click the "Select Run/Debug configuration" box in toolbar.
  2. Click "Edit configurations..."
  3. Select the test class at left hand side
  4. 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"
  5. Click "OK"

Then run the test again.

@clydzik
Copy link
Author

clydzik commented Jul 20, 2017

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.

@clydzik
Copy link
Author

clydzik commented Jul 20, 2017

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.

@clydzik
Copy link
Author

clydzik commented Jul 20, 2017

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.

@hkhc
Copy link
Owner

hkhc commented Sep 22, 2017

Version 0.6 should work with @config properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants