Try this: go to GitHub. Search for any open-source Android app you can think of. OK, now take a look at the app’s unit tests. Yes, the unit tests.
No unit tests? (Other than the one generated by Android Studio…)
So why don’t people unit test Android applications?
I’ll guess it’s because of any combination of these factors:
- The Android platform itself doesn’t really lend itself well to unit testing. For example, your class that represents a screen, extends the Activity class, and you can’t just construct an activity yourself in a unit test, you need to write your test as an Android Instrumentation Test which requires an emulator or a physical device to run the test.
- Running Android tests (or even Lint checks or anything with Gradle) is super slow! Really really super slow if you’re coming from a .NET or Web background.
- Pure unit test support (i.e. JVM / JUnit4 tests without the need for an emulator or device) was only released in Feb 2015. Several years since people started writing Android apps and tests. Unit testing support is fairly new and it will take a while for people to adopt this new mindset.