I have a instrumentation test that uses test data. I have included this test data as an asset file in the test project, and it works well.
I would like to speed up re-running the test with different test data by just pushing the test data file to the internal storage of the test app and then let the test read the test data from the internal storage if it exists.
However, I am unable to access the internal storage from the test app. I am using a subclass of android.test.InstrumentationTestRunner
, and all calls to getContext().getFilesDir()
return null
.
Are test apps not able to access the internal storage?
Any help is greatly appreciated.
If you happen to use Roboguice with your tests, make sure you implement the constructor of your application class like this:
public MyApplication(Instrumentation instrumentation) {
this();
attachBaseContext(instrumentation.getTargetContext());
//this does not work:
//attachBaseContext(instrumentation.getContext());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With