A new functionality is not complete without being tested first. We, as developers, have fallen many times into the trap of submitting code changes without writing a passing test first, only to find that the expected behavior was broken on future iterations.
We learned the hard way that writing tests boosts our productivity, increases code quality, and helps us release more often. For this reason, Android provided several tools to help us test our apps from the early stages.
In the following two sections, we will talk about my favorite setup, Robolectric for unit testing and Espresso for integration testing.
Until Robolectric, writing unit tests meant that we had to run them on a real device or an emulator. This process could take several minutes as Android build tools have to package the testing code, push it to the connected device, and then run it.
Robolectric alleviates this problem by enabling us to run our unit tests in the JVM of our workstation...