[英]How do you get access to a testing device's files when running instrumentation tests for Android
I have set up a physical device with files that can be retrieved through the MediaStore.我已经设置了一个物理设备,其中包含可以通过 MediaStore 检索的文件。 My goal is to retrieve these files through the MediaStore in an instrumented test.我的目标是在仪器测试中通过 MediaStore 检索这些文件。
Currently, when I push the debug app to the device and test it manually, the device files are found.目前,当我将调试应用程序推送到设备并手动测试时,会找到设备文件。 The problem is when I am running instrumentation tests, and I get nothing from the MediaStore.问题是当我运行仪器测试时,我从 MediaStore 中一无所获。
Is there a way to get the files through the MediaStore in an instrumentation test?有没有办法在仪器测试中通过 MediaStore 获取文件?
Possible relevant: I define and use a dummy Activity in my instrumentation test class可能相关:我在我的仪器测试 class 中定义并使用了一个虚拟活动
Looper.prepare()
dummyActivity = DummyActivity()
I then tried to define the dummy Activity in the debug folder, declare it in the debug manifest, and instantiate it via an ActivityScenario.然后我尝试在调试文件夹中定义虚拟 Activity,在调试清单中声明它,并通过 ActivityScenario 实例化它。 Didn't help.没有帮助。
I made the assumption that manifest permissions carried over to test package from the debug package.我假设清单权限从调试 package 转移到测试 package。 Not so.不是这样。
Adding the following line to my test class made the MediaStore query return the files on the device!将以下行添加到我的测试 class 使 MediaStore 查询返回设备上的文件!
@get:Rule
var mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.