Friday, May 18, 2012

Test-Driven Android

Lately I have been talking a lot about unit testing Android code. Mostly to myself. But occasionally in front of an audience.

There is no perfect solution, but by far the best one I have found is Robolectric. This open-source framework created by Pivotal Labs (contributed to by many) allows you run unit tests against your Android code in the JVM. This is a big win for test-driven developers like myself.

Here are slides from two presentations I have given in recent months. Sample code from the String Bling project is available on GitHub. It illustrates unit testing three different ways: Using the Android SDK Testing Framework (Instrumentation), plain old JUnit, and Robolectric.

The first presentation was given at the Android Alliance Philadelphia meetup group on January 25th.

The second (shorter) version is from the Mobile Lightning! event on April 24th during Philly Tech Week 2012.

2 comments:

  1. On your first presentation I think you should have included Monkey testing. If you'd seen the apkudo presentation from AnDevCon II, they sell Monkey testing as "better than nothing", which puts it between the second and third points in slide 21.

    ReplyDelete
    Replies
    1. Thanks for the suggestion. Originally I talked about Monkey and MonkeyRunner in the "Other" section but it probably does deserve its own bullet point.

      Delete