Real unit testing with Robolectric
So far, we saw how to run Android unit tests using Maven in an emulator or a real device (smart phone, tablet, and so on). If you have followed the examples provided in this chapter, you should have noticed by now that running activity unit tests is quite slow. Every time we need to follow the cycle of building the project, then deploy this to the device/emulator, and finally launch the application and run the tests. This automatically is done by Maven, but it is clearly not according to one of the core concepts of Unit testing: Run tests fast!
There must be a more clever way to do this, and it has a name from the future: Robolectric (http://robolectric.org/) is an Android unit testing framework that lets us run unit tests inside the Java Virtual Machine (JVM) of our development environment in a couple of seconds without the need of Android SDK. And it's getting even better. We can use our favorite JUnit 4 style to run our test classes, which is far...