Using specific resources for android testing
I'm trying to test an android project. I'm using intellij IDEA.
So far everything goes perfect. My problem arises when I try to use a different xml resource file for the tests (with specific data for testing) instead of using the XML resource from the tested project.
I have the following directory structure:
Project
| |---- assets |---- res |-------|---- values |-------|---- xml开发者_JAVA技巧 |---- src |---- tests ---------|----res ---------|------|-----xml ---------|-----srcI've assumed that the XML stored in the Project/tests/res/xml would automatically replace the one stored in Project/res/xml when running under the context of the test. It is not happening so, the tests keep on taking the Project/res/xml file instead of the test xml.
Do I have to make anything additional? Is there a way to somewhat mock this?
Thanks!
Certainly you can place your XML files in the resource
or assets
folder of your test project and access them by:
InputStream myxml = getInstrumentation().getContext().getAssets().open("my_document.xml");
精彩评论