I have the following folder structure in Android Studio:
├── androidTest
│ ├── java
│ └── res
│ └── raw
│ └── test_file
└── main
├──
By default your androidTest project will include your app's R class, but androidTest's resources will be generated into a separate file. Make sure you import the R class from your test project:
import com.your.package.test.R;
[..]
getInstrumentation().getContext().getResources().openRawResource(R.raw.test_file);
You can also directly reference the test project's R class:
getInstrumentation().getContext().getResources().openRawResource(com.your.package.test.R.raw.test_file);