开发者

How do I access the internal storage from a test project?

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 t开发者_开发知识库est 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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜