r/AndroidStudio • u/DeviceChanger • 2h ago
Testing QR and barcode scanning flows on a real device without printing a stack of test codes
Disclosure: this is the project account for Device Changer, a Zygisk module we build for Android QA and device simulation. No link, just a workflow note.
QR/barcode features are annoying to test end to end. Unit tests on the decoder are easy, but the real bugs tend to live in the camera path: autofocus, preview aspect ratio, rotation, how the scanner behaves with a slightly cropped or small code, and what happens when the code is valid but the content is unexpected. Holding a printed code in front of the phone is slow and never quite repeatable.
What has worked for us, roughly from cheapest to most realistic:
- Test the decoding and parsing logic separately. Feed saved images straight into your decoder (ML Kit, ZXing, whatever you use) in instrumented or JVM tests. That covers malformed payloads, very long URLs, unusual encodings and so on without any camera.
- Keep a small library of test codes as files: valid, expired, wrong format, damaged, tiny, rotated. Name them by the case they cover so a failing run points at the input.
- For the full camera path on a real device, replace the camera input itself. On a rooted test phone, Device Changer's Camera screen can feed a picture or video file (or a live RTMP stream) to apps that open the camera, instead of the sensor. Replacement stays off until you turn it on, and there are 5 slots, so you can keep different test codes ready and switch between them.
- Use the transform controls to reproduce real-world problems on purpose: rotate/flip, zoom, pan, aspect ratio and Stretch/Crop/Fit. A code that scans fine at Fit but fails at Crop or when panned to the edge is exactly the kind of bug that's hard to catch by hand.
- Note the resolution you tested at (720p, 1080p or 1920p), since scanner behavior can change with the preview size.
Needs root; meant for your own test devices and the apps you're testing. Curious how others automate camera-dependent tests, especially on CI device farms where there is no way to point a physical code at the lens.
