jlhonora jlhonora - 4 months ago 51x
Android Question

Android test raw resource

I have the following folder structure in Android Studio:

├── androidTest
│   ├── java
│   └── res
│   └── raw
│   └── test_file
└── main
├── java
└── res
└── raw
   └── app_file

I'm trying to access the
resource which exists in the raw folder of the androidTest elements. Here's the code inside a Robotium test case that inherits from

InputStream is = this.getInstrumentation()

Android Studio throws a reference error since the resource cannot be found. The exact error is "Cannot resolve symbol test_file".

How can I reference this resource form a test case, which exists on the androidTest resources bundle?


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;



You can also directly reference the test project's R class: