Code_Yoga Code_Yoga - 6 months ago 13
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


'src/androidTest/res/values'


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(Resources.java:1382)
at android.content.res.Resources.getString(Resources.java:1476)


Can somebody point out where I am going Wrong ??

Answer

In your build.gradle file, this should work:

sourceSets {
    instrumentTest.setRoot('tests')
}

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