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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With