Unit Testing Android Applications Multunus Software Pvt. Ltd. Leena SN Krishnaprasad R Agile Software Development Head of Engineering Software Architect @multunus @leenasn @krikrn
Demo of AndroidUnitTestCase
AndroidInstrumentationTestCase ● Extension to JUnit ● Provides wrappers for instantiating Activities ● Provide methods for interacting with Activities
The Problem ● Slow tests ● Resulting in slow iterations
The Solution ● Mocking ● But its not easy :(
Mocking is Hard because.. ● Google has stripped all the classes with android.jar with RuntimeException(“Stub”) ● Most classes and methods are final ● Non public constructors ● Lack of interfaces ● Many static methods
Why Robolectric? ● Faster tests - runs in JVM ● Emulates Android SDK and Resources
Lets see it in action!
How it works ● Emulates Android SDK, modified to run it on JVM Using ○ Shadow Objects ○ View and Resource Loading
What is Special ● Extending Robolectric is easy too ● Awesome Community Support
What Robolectric is NOT ● Never runs on actual device as it emulates the environment ● It can test small units, so can not replace automated integration tests ● The above are for purpose :)
Summary
References http://bit.ly/android-robolectric http://bit.ly/how-robolectric http://bit.ly/multunus-robo-sample http://bit.ly/robolectric-blog

Droid con 2013 workshop unit testing in android [robolectirc]