Skip to content

Latest commit

 

History

History
12 lines (7 loc) · 1.45 KB

README.markdown

File metadata and controls

12 lines (7 loc) · 1.45 KB

Spring Android and Robolectric Sample

This is a simple application that showcases how to use Robolectric to test Android applications with Spring Android. Robolectric includes shadows for most of Android's API, but it does not cover the Apache HttpComponents classes that Spring Android makes use of.

I originally tried to create shadows, but found out that Robolectric does not shadow those classes, as it only restricts shadows to certain packages as seen in AndroidTranslator.

Amazingly, the solution is to simply mock RestTemplate. This simple application adds a layer of indirection to RestTemplate so it can be mocked using Mockito.

Note that when using IntelliJ IDEA you will need to rearrange the dependency order in order to run the test in the IDE. This is because the Android dependency is listed first, and it includes stubbed implementations as well as an older JUnit (3.x) library. The following libraries should be moved up before Android:

  • junit-4.10.jar
  • httpcore-4.0.1.jar