Dockerizing Calabash Android Testing on macOS
Article Summary
Rajdeep Varma from Badoo (now Bumble) tackled a problem that sounds impossible: running Android device tests inside Docker on macOS when Docker can't even see USB devices. The workaround? Brilliantly hacky.
Badoo's QA team wanted developers to run Calabash Android tests in one command without complex environment setup. Docker was faster than Vagrant, but macOS Docker doesn't support USB—a dealbreaker for ADB communication with Android devices. This article details the creative networking tricks that made it work.
Key Takeaways
- Docker for Mac can't access USB, blocking ADB from detecting Android devices
- Solution: Run ADB server on Mac host, proxy connections into container
- Port forwarding hack redirects network traffic to localhost using pfctl rules
- Final setup requires only ADB installed locally, everything else containerized
By combining an ADB proxy server and network interface forwarding, the team containerized their entire Android test suite while keeping just one small dependency on the host machine.
About This Article
Calabash-Android uses Ruby code that relies on ADB port forwarding to reach an HTTP server running inside Android devices. Docker containers can't access localhost:xxxx ports when they're only bound to the Mac host's 127.0.0.1 interface because of how Docker for Mac handles networking.
Rajdeep Varma's team set up pfctl packet filtering rules to redirect traffic from network interfaces like lo0, en0, and en1 to localhost port 34778. This allowed containers to communicate with devices through the host's forwarded ports.
Developers can now run the entire Calabash test suite with one command: ./started.sh path/to/your.apk features/my_feature/awesome.feature. They only need ADB as a local dependency, which means no more wrestling with JDK, Android SDK, and Ruby installation.