Walmart Abha Gupta Jun 30, 2016

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

Critical Insight

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.

The article includes complete code examples and a working GitHub repo showing exactly how to configure WireMock with HTTPS support for Android.

About This Article

Problem

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.

Solution

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.

Impact

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.