How to access the internal storage from a test project?

I have a test test that uses test data. I included this test data as an asset file in the test project and it works well.

I would like to speed up the restart of the test using different test data by simply pushing the test data file into the internal memory of the test application, and then let the test read the test data from the internal storage, if it exists.

However, I cannot access the internal storage from the test application. I use a subclass of android.test.InstrumentationTestRunner and all calls to getContext().getFilesDir() return null .

Are test applications inaccessible to internal storage?

Any help is greatly appreciated.

+4
source share
1 answer

If you use Roboguice with your tests, make sure that you implement the constructor of your application class as follows:

 public MyApplication(Instrumentation instrumentation) { this(); attachBaseContext(instrumentation.getTargetContext()); //this does not work: //attachBaseContext(instrumentation.getContext()); } 
+1
source

All Articles