Robolectric is a testframework for Android that let you test your applications graphical components inside unit tests. Lets say we have this really simple application that prints “hello world” in dialog box when clicking a button. The regression way of testing it would be. Boot the emulator up (boring), manually click and verify that the text actually is the expected.

This could be automated with these lines of code. Besides from some imports and setups it would look like this:

All robolectric tests come with the compulsary class-annontation:

Compared to regression testing this is of course far superior. But compared to instrumentation test libraries  (like robotium), what are the benefits. I think you get momentum from that the test executes faster and you write these kind of tests the same way as your regular vanilla unit test cases. This is true TDD imho.

Supports Eclipse, IntelliJ and Maven.

Resources:
http://pivotal.github.com/robolectric/

 

Adsense