How can I access source resources in Android test projects?

This is my test class:

public class AndroidTunerTest extends ActivityInstrumentationTestCase2<AndroidTunerActivity> { [...] } 

But I can’t access the context of my test project, I can only access the context of the activity that I want to test. Therefore, I do not know how to read resources in the same way as mentioned here:

Android, how to access the source resources that I installed in the res folder?

I do not want to link all the test resources in my main application, because testing has very large files that are not related to the real application.

What can I do?

+6
source share
1 answer

Got it ...

 this.getInstrumentation().getContext().getResources().openRawResource(R.raw.blah_blah); 

I had to debug and analyze the ActivityInstrumentationTestCase2 inheritance tree a bit.

+4
source

Source: https://habr.com/ru/post/895404/


All Articles