Droidcon India 2013

What's your thinking on Android this year?

Leena S N

Leena S N

@leenasn

Unit Test your Android application using Robolectric

Submitted Sep 30, 2013

This workshop is for giving an overview on how to write faster, maintainable and behavioural tests using Robolectric, an Android Unit Testing Framework. At the end of the session, the attendees should be able to:

  • Learn about basic Android Unit Testing and understand the issues with the default AndroidTestRunner
  • Overview of Robolectric
  • How to write tests using Robolectric and run it in JVM [i.e. instead of Dalvik]
  • How to integrate Robolectric tests with your Continuous Integration Server such as Jenkins

Outline

Android SDK comes with a testing framework called Android Instrumentation Runner which is written on top of JUnit. The problem with it is that it is slow as it requires dexing (i.e. converting into Dalvik Executable), packaging and installing on the actual device or emulator. This can become a bottleneck as unit tests are expected to run fast.

Running the tests in the JVM is not possible by just mocking because, the actual class definitions are available only in Dalvik and not in android.jar which the SDK provides. The android.jar throws RuntimeException for all the methods, and its tough to mock or extend because of the way the Android SDK is designed.

Robolectric on the other hand has rewritten Android SDK classes so they can run in the JVM. It also handles inflation of views (i.e. creating views from the xml file), resource loading, and lots of other stuff that’s implemented in native C code on Android devices. This allows tests to do most things you could do on a real device. It’s easy to provide our own implementation for specific SDK methods too, if needed.

The workshop is intended for anyone who wants to write Android Unit Tests as FIRST (Fast, Isolated, Repeatable, Self-Veifying and Timely)

Requirements

  1. Wisdom wise:
    • Experience with Android Development
    • Familiarity with TDD will be an added advantage
  2. Hardware wise:
    • You have to bring your own laptop (don’t forget the charger)
    • Please bring your own Android device to test out your apps on them in real time
    • Make sure your machine configuration is reasonable enough to withstand the dev environment.
  3. Software wise:
    • Operating System: Windows XP (32bit), Windows 7 (32 /64 bit), Windows 8 (64 bit), Mac OS X 10.5.8 or later (x86 only) or Linux (tested on Ubuntu Linux, Lucid Lynx)
    • Eclipse IDE (or Participants can directly download platform specific ADT Bundle from http://developer.android.com/sdk/index.html)
    • Eclipse 3.6.2 (Helios) or greater
    • Note: Eclipse 3.5 (Galileo) is no longer supported with the latest version of ADT.
    • Eclipse JDT plugin (included in most Eclipse IDE packages)
    • JDK 6 (JRE alone is not sufficient) with latest update needs to be installed
    • Android Development Tools plugin (recommended)
    • Preferred Android SDK version is 4.2.2 i.e. API Version 17
  4. Note: Specific libraries required for the workshop will be shared during the workshop.

Speaker bio

Leena is the Head of Engineering @ Multunus. She was bitten by the TDD bug a couple of years ago. Since then she’s moved onto Continuous Delivery (CD) in a big way - even spoke about CD at DroidCon India 2011 and AgileIndia 2012. Having done enough TDD in Ruby/Rails, Javascript/Backbone/Angular - she’s now keen on conquering the Android world.

Krishnaprasad, alias KP, is the Senior Software Architect @ Multunus. His technical expertise ranges from J2EE, Ruby On Rails on the Webapp technologies to Android Native and Hybrid apps. He is a big fan of TDD too. He has also spoken at Droidcon India 2011. He is all set to educate the world with his knowledge about the Android universe.

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('Post a comment…') }}
{{ gettext('New comment') }}
{{ formTitle }}

{{ errorMsg }}

{{ gettext('No comments posted yet') }}

Hosted by

droidconIN is an annual conference on Android, part of the worldwide series of events. more