Many Android developers manually test their applications on the emulator or the device. This process is slow, tedious and prone to errors. This is a time consuming process involving building, deploying and testing the application, not to mention a debugging nightmare. Automation testing of Android application with Robolectric can reduce the time taken to develop the application significantly.
However there are several approaches for automation testing of an android application. Some of them are :
- Android JUnit Tests
- Robotium
- Android UI Testing Framework
- Robolectric
Android JUnit Tests require an emulator or a device. Developers frequently run into the “java.lang.RuntimeException: Stub!” exception when they try to run the Android.jar file against their unit tests since the implementation in the Android.jar file is completely stubbed out. This approach is slow and is difficult to configure on a build server. This is not easy to use, we need to extend base classes that are JUnit 3 subclasses.
Robotium is another option but it requires an emulator or device too. Robotium test framework is more suited for functional and black-box testing of android applications. It’s still not clear if Robotium will complement or be superseded by standard Android UI testing framework.
Android UI Testing Framework is complex to setup and requires a device for testing. In addition, its complex to configure on a build server. It is more suited to functional and black-box testing for a variety of target devices. Since it was recently released it needs time to stabilize.
Robolectric provides a simple approach to automating unit testing on Android by using standard JUnit tests. It runs on any JVM, without needing the emulator or a device. Robolectric is also relatively easy to configure on a build server.
Robolectric has dedicated JUnit TestRunner for classes that use the Android API. Robolectric also silently replaces Android.jar stub implementations with its own shadow implementations. Developers can use @RunWith – the RobolectricTestRunner (or subclass) to enable this. Robolectric doesn’t work in every case. Shadow classes either do not exist for every Android class or are incomplete. When integrating with Emma – the code coverage tool, make sure the RobolectricTestRunner (or subclass) is used with every test, otherwise weird classpath behavior may be observed.
Further reading:
Android Recipes – A Problem Solution Approach – An excellent book for learning Android development with practical examples
Android Application Testing – Provides a good introduction to Android Testing, though slightly dated
Reference:
http://eclipsesource.com/blogs/2012/09/25/advanced-android-testing-with-roboguice-and-robolectric/
http://robolectric.blogspot.com/
Other popular articles:
- What is Testing and Configuration Management in Agile development?
- Monkey testing- Examples, Differences, Tools,How To Do, Advantages, Disadvantages, Types
- What is Test harness/ Unit test framework tools in software testing?
- Mobile application development and testing checklist – 17 points to remember before developing an app
- Mobile Application Security Testing Approaches – Beginners Guide
android apps development says
Excellent post.this post is very useful for android developer.
ISTQB Guide says
Thank you, glad you found it useful