Code_Yoga Code_Yoga - 1 year ago 123
Android Question

Android : Separate resources for 'androidTest''

I want to use separate set of Resources while running test, so I set up a file named 'configs.xml' in


and added this to gradle

sourceSets {
androidTest {
resources.srcDirs = ['src/androidTest/res'] }
} }

But when I try to fetch the resource using the below line

String s1 = getInstrumentation().getContext().getResources().getString(R.string.test_config);

I get this below error

01-08 18:06:13.814 16761-16774/com.example.hellodroid I/TestRunnerīš• android.content.res.Resources$NotFoundException: String resource ID #0x7f070008
at android.content.res.Resources.getText(
at android.content.res.Resources.getString(

Can somebody point out where I am going Wrong ??

Answer Source

In your build.gradle file, this should work:

sourceSets {

This allows, I believe, tests/java, tests/res folders etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download