开发者

Storing test files in the test project

I wrote some tests that use XML files. I have two project one with code, the second with tests. I would like to store this XML files (they contain some data used during the tests) in the test project. But it is not possible because it seems that only files from src projec开发者_Python百科t are loaded to a device. Does anyone know the way to solve this problem ?


Suppose you got assets folder in both android project and test project, and you put the XML file in the assets folder. in your test code under test project, this will load xml from the android project assets folder:

getInstrumentation().getTargetContext().getResources().getAssets().open(testFile);

This will load xml from the test project assets folder:

getInstrumentation().getContext().getResources().getAssets().open(testFile);

Make sure your TestCase class extends android.test.InstrumentationTestCase instead of android.test.AndroidTestCase to access this.getInstrumentation() method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜