Android:注入假相机预览以进行测试 [英] Android: Inject fake camera preview for testing purpose

查看:207
本文介绍了Android:注入假相机预览以进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些在物理android设备上运行的黑盒验收测试.被测应用程序(AUT)依赖于相机的预览.具体来说,它使用android.hardware.Camera类的setOneShotPreviewCallback方法.我正在寻找一种方法来注入伪造的预览图片以测试应用程序的行为.

I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback method of the android.hardware.Camera class. I am looking for a way to inject a fake preview picture to test the app's behavior.

我以为我可以通过将测试代码调用AUT的PreviewCallback对象来欺骗Camera对象,但是不幸的是,实例变量mPreviewCallback是Camera对象专用的,因此我的测试代码无法获取对PreviewCallback对象的引用.

I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback object, but unfortunately, the instance variable mPreviewCallback is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback object.

我想到的另一种方法是将Message发送到Camera的EventHandler,但是字段mEventHandler再次是私有的,因此测试代码无法获取对Handler的引用.

Another way I thought about was to send a Message to the Camera's EventHandler, but again the field mEventHandler is private, so the test code has no way to get a reference to the Handler.

推荐答案

请参阅 Android模拟相机如何在Android Emulator Camera中模拟图片这两种方法都不需要root设备,但是需要更改应用程序.我相信,即使您无权访问源代码,也可以通过反编译dex来进行必要的修改.

Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.

这篇关于Android:注入假相机预览以进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆