在测试项目中存储测试文件
我编写了一些使用 XML 文件的测试。我有两个项目,第一个是代码,第二个是测试。我想在测试项目中存储这个 XML 文件(它们包含测试期间使用的一些数据)。但这是不可能的,因为似乎只有 src 项目中的文件才会加载到设备中。有谁知道解决这个问题的方法?
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 project are loaded to a device. Does anyone know the way to solve this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设你在android项目和测试项目中都有assets文件夹,并且你将XML文件放在assets文件夹中。在测试项目下的测试代码中,这将从 android 项目资产文件夹中加载 xml:
这将从测试项目资产文件夹中加载 xml:
确保您的 TestCase 类扩展了
android.test.InstrumentationTestCase
而不是android.test.AndroidTestCase
访问this.getInstrumentation()
方法。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:
This will load xml from the test project assets folder:
Make sure your TestCase class extends
android.test.InstrumentationTestCase
instead ofandroid.test.AndroidTestCase
to accessthis.getInstrumentation()
method.