android - 访问测试应用程序资产

发布于 2024-09-27 00:42:24 字数 232 浏览 0 评论 0原文

我的测试应用程序的资产目录中有一个 XML 文件。我想从测试类的套件方法访问此文件。

即,

公共静态 TestSuite suite(){ InputStream Stream = // 返回资源的一些代码 知道

我该怎么做吗?我尝试使用 Resources.Resources.getSystem().getAssets() 但没有运气:-(。请帮忙。

感谢 adv, 约瑟夫

I've an XML file in the assets directory of my test application. I want to access this file from my suite method of the test class.

ie.,

public static TestSuite suite(){
InputStream stream = // Some code which returns the asset
}

Any idea how I can do this? I tried with Resources.Resources.getSystem().getAssets() but no luck :-(. help please.

Thanx in adv,
Joseph

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不吻晚风 2024-10-04 00:42:24

我的测试应用程序遇到了同样的问题。不幸的是,看起来测试用例类中的 getContext() 实际上返回了被测应用程序的上下文。为了获取测试应用程序本身的上下文,您必须继承 InstrumentationTestCase ,然后调用 getInstrumentation().getContext() 来获取测试应用程序的上下文。

I encountered the same problem with my test app. Unfortunately, it looks like getContext() in a test case class actually returns the context of the application under test. In order to get the context of the test application itself, you have to inherit from InstrumentationTestCase and then call getInstrumentation().getContext() to get the context of the test app.

爱殇璃 2024-10-04 00:42:24
final AssetManager assetMgr = context.getResources().getAssets();

final InputStream fileIn = assetMgr.open("my_file.txt", AssetManager.ACCESS_STREAMING);

我们也可以使用此方法 链接xml 文件的文本

final AssetManager assetMgr = context.getResources().getAssets();

final InputStream fileIn = assetMgr.open("my_file.txt", AssetManager.ACCESS_STREAMING);

We can use also this method link text for xml-file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文