Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Inject fake camera preview for testing purpose

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.

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.

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.

like image 480
lacton Avatar asked Dec 16 '13 18:12

lacton


People also ask

What is image injection?

Inject an image. On an open device, you can inject an image to mock the use of the camera. This is helpful for testing application actions, such as focus or image placement, in apps that rely on camera usage, for example barcode readers or bank check scanning apps. Image injection supports uploaded images in .


1 Answers

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.

like image 199
Alex Cohn Avatar answered Oct 21 '22 12:10

Alex Cohn