Member-only story
Writing a Fully Unit Testable Android App
The journey begins at the start of your project

Sometimes, you have to say it straight: Google does not build Android with unit testing in mind. Even as recently as API 30, the platform continues to evolve in this unfortunate direction, making critical components of your app increasingly challenging to test. Thus, if you want to build an app with 95% or higher code coverage, then the burden lies with the app developer to make this a reality.
Yet is it such a burden to achieve such a respectable amount of code coverage? I would argue this is only a perceived burden, one which an engineer can reduce with a bit of discipline by following best practices.
The Blueprint
These concepts are effectively the TL;DR version of this article since they form the basis of every pattern I will discuss:
- Extract as much logic as possible from classes that inherit from Android APIs
- Interact with Android APIs through forwarders and factories
- Isolate the code you plan to exclude from testing (???!!?!!) More on this later.
It turns out that some architectural patterns seem to lend themselves automatically to this blueprint. Thus, it makes these concepts quick to adopt, and the…