android-studio-unit-test-plugin icon indicating copy to clipboard operation
android-studio-unit-test-plugin copied to clipboard

Resource files not picked up in test variant

Open realdadfish opened this issue 10 years ago • 10 comments

Robolectric allows to place its configuration in a special config file org.robolectric.Config.properties that usually resides in src/test/resources. While this is correctly picked up when I execute ./gradlew test on command line, it isn't when I run the test through Android Studio.

realdadfish avatar Jul 09 '14 16:07 realdadfish

Right now, test resources are not supported at all.

evant avatar Jul 15 '14 17:07 evant

Hi, is there any progress to that issue? I'd also need that feature :-) Matthias

klassm avatar Aug 09 '14 17:08 klassm

@klassm No work so far. I do have a rough idea of what needs to be done.

evant avatar Aug 09 '14 17:08 evant

Well this would be absolutely a wonderful feature :-)

klassm avatar Aug 10 '14 11:08 klassm

I did make a bit of progress on this. Resource directories are now marked correctly if you are on the latest version of the gradle plugin. However, they are still not added to the classpath. I think its because the build dir is set up differently than a standard java project due to flavors. I can't seem to find a way to modify the classpath of the test runner to account for this. If you are really dieing for this feature, you could probably hack something together with a task that copies the resources into test-classes.

evant avatar Aug 25 '14 05:08 evant

@tommyd3mdi @klassm This will probably never be implemented because it requires recreating the entire classpath for the junit test runner. Intellij 14 has a new gradle test runner that solves this (and several other problems). So your best bet is to use that, or wait until the changes get rolled into Android Studio.

evant avatar Sep 14 '14 23:09 evant

Ok great. Thanks!

klassm avatar Sep 15 '14 09:09 klassm

Reopening so others can find it.

evant avatar Sep 15 '14 12:09 evant

Actually (AS 1.0-RC) the main resource folder it's find correctly, but their flavor counterpart not

ffgiraldez avatar Nov 24 '14 14:11 ffgiraldez

You can fix this by copying the test resources via build.gradle:

//Copy test resources to classpath folder. See https://code.google.com/p/android/issues/detail?id=74443
tasks.findByName("assembleDebug").dependsOn("copyTestResources")
task copyTestResources(type: Copy) {
    from "${projectDir}/src/testDebug/resources"
    into "${buildDir}/test-classes/debug/resources"
}

polson avatar Dec 08 '14 21:12 polson