Android Testing with Mocking
Article Summary
Abha Gupta from Walmart Global Tech tackles one of Android testing's toughest challenges: running mock servers inside your APK for reliable device farm testing. No external dependencies, no flaky tests.
When scaling Android tests across device farms, traditional mock server approaches fall apart because there's no application server to start. Gupta's team investigated multiple solutions and adapted WireMock to run directly inside Android apps, solving the HTTPS challenge with BKS keystores.
Key Takeaways
- WireMock runs on Jetty, making it perfect for embedding in Android APKs
- Android requires BKS keystores instead of Java's standard JKS for HTTPS
- Mock server runs inside the app itself, enabling true parallel test execution
- Custom SSL context factory bypasses Android's missing endpoint identification methods
By embedding WireMock directly in Android test APKs with BKS keystore support, teams can create massive parallel test suites that run reliably in device farms without external mock server dependencies.
About This Article
Android native apps don't have a built-in application server to run mock servers during CI/CD, so teams either pay for external hosted mock services or deal with flaky tests on device farms.
Abha Gupta's team put WireMock directly into Android APKs by using a Jetty container. They wrote a CustomizedSslContextFactory class to work around a missing setEndpointIdentificationAlgorithm method that Android's SSLParams doesn't have.
Teams can now stub HTTPS endpoints at 127.0.0.1:9943 using BKS keystores stored on /sdcard/. This lets large test suites run in parallel without needing external services or separate mock server instances.