Your path is wrong. The path you want is src/androidTest/res/raw
.
Files in this directory will replace files in the src/main/res/raw
.
New files in this directory, need to be accessed by the R class in the test package and not the app's R file.
-- update
If the problem is that the Android Studio tells you that the R class does not exist in the test package, then that is caused by Android Studio not building the test R class until you try to run the unit tests. Fix this by ignoring the errors on the screen and try to run the test. The R class will be generated and the tests will run (assuming the were no other errors).
If the problem is that reading the file produces the wrong contents, then you're reading the file from the wrong context. You need to use getContext from Instrumentation.
public class ResourceLoadTest extends InstrumentationTestCase {
public void testLoadResource() throws IOException {
InputStream inputStream = getInstrumentation().getContext().getResources().openRawResource(com.example.app.test.R.raw.hello);
try {
Scanner scanner = new Scanner(inputStream, "UTF-8");
assertEquals("hello", scanner.nextLine());
} finally {
inputStream.close();
}
}
}