Setting Dir Resource for Robolectric Test Cases

I would like to use a different resource directory for one of my Robolectric test cases. In this case, I would like to use the resources of the release variant. The thing is, I can't seem to get this to work and I don't see any examples on the internet of anyone using this config. It still uses debug resources (Im running gradle testDebug where "Debug" is one of my buildTypes in Gradle). The parameter I am setting is correct relative to the directory the manifest is in. I tried referencing the ref files in "build / intermediates / ..". The config doesn't seem to have any effect.

@Config(resourceDir = "../../variant_resources/release/res")


public void testHowThingsAreUsingReleaseResources() {


Im using Robolectric 2.4-SNAPSHOT Anyone have any luck with this configuration? Is there an obvious mistake?


source to share

1 answer

Qualified resources

If the resource file needs to change depending on the subfolder, then a resource qualifier can be specified. See the RoboElectric page in Skilled Resources .

A @Config

parameterized attribute qualifiers

can be used to specify a resource qualifier.

For example, if there are resources:



... then the attribute @Config(qualifiers="en-port")

will guarantee that the resource will be used values-en-port/strings.xml


Modifying resource paths using a different RobolectricTestRunner

Another approach to loading different resources (if only for some tests) is to implement a different class implementation RobolectricTestRunner

that loads different resource paths. Here's a good example of how to do it here: / ...



All Articles