Android Testing

October 15, 2014

I’ve recently started looking at the Android testing framework and once again I have to say I like it, I’m impressed with the set of tools available.

I won’t say too much about it as it’s covered pretty comprehensively in the Android documentation here: http://developer.android.com/tools/testing/index.html (note some of this stuff, namely the tutorial is pretty out of date, SDK 8, but it is still valid), and here: http://developer.android.com/training/testing.html.

What I will say right now is that if you’re not testing your code as soon as you begin writing your code at the very latest (many proponents of Test Driven Development advocate writing your unit tests before you start writing application code) you should be, really, you should (I intend to make the case for unit testing in another post sometime).

The Android SDK tools make it really easy to start testing, they provide everything you might need in terms of base test classes, mocks, instrumentation and automation. The documentation gives guides on what to test and how to test.

With all of these tools built into the SDK it would be foolish not to use them. If you’re new to Unit Testing and Software Testing in general I think this could be a really good place to start.

For me personally, having such a comprehensive framework in place immediately removes any barriers to unit testing (Unit Testing can be hard at times :(, sometimes it seems that I put more time into writing tests and the conditions under which they can run than actual application code), quite simply there are no excuses for me not to do it here.

Some things what I likes:

  • Familiar – Based on JUnit, anyone who has used JUnit and it’s test runner should be comfortable straight away.
  • Built in Instrumentation for testing Activity lifecycle and UI components – To try to do this from scratch would be incredibly tedious.
  • Comprehensive mocking framework – There is a good set of system mock objects that can be used for dependency injection. Often external dependencies of classes can cause difficulties in testing, providing mock objects helps alleviate this, having a ready made set of mocks to extend is very helpful.
  • UI automation – Great for automated system/functional testing, anyone who has had to run manual regression tests on Software UIs will appreciate this.
Advertisements