Skip to content

ealden/spring-android-robolectric-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Spring Android and Robolectric Sample

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published