Unit Testing: Android Test Framework vs Robolectric Test Framework

Ok, so I don’t have a huge amount of testing experience but I really want to get hands on with this project. I’m going to start off with Unit Tests and move on from there.  For testing an Android application I have two options here:

  • Native Android Test Framework
  • Third-party Robolectric Test Framework

After doing some research on both, I settled on using the Robolectric Framework. My reasoning behind this is that the Robolectric JUnit tests run on a local JVM (my lappy), whereas the Android Test Framework requires an Android device / emulator. This isn’t a huge problem, but it does slow down development (as tests running on my machine will be considerably faster in comparison to an emulator). On the other hand, using a real device gives you a more realistic portrayal of test execution time on an actual device rather than my local JVM. In summary, here’s why I’m choosing Robolectric:

  • Speed: Tests run on local JVM rather than emulator/device.
  • Flexibility: I can mock almost any Android feature (sqlite etc)
  • JUnit 4, Android Test Framework is still on JUnit3

To conclude, I’m using Robolectric for development purposes but when the system moves from the development stage to the release stage, I may use the native testing framework for a more realistic test experiance.

Share This