Android unit test case automation: Robolectric vs Android Testing library

It's amazing which one is better for recording unit test applications for Android applications and libraries: using the Robolectric library or binding to the Android Testing platform. I want to run a test package on the command line and I want it not to depend on the need to configure the emulator or connect the device with the assembly. Do any of you do a comparative analysis of both of them, or is something better? Your experience will be very useful to me to decide on the best solution.

+43
android unit-testing junit continuous-integration robolectric
Feb 19 '13 at 3:45
source share
2 answers

I use a tiered system where, whenever possible, I prefer earlier levels:

  • Pure unit tests. I try to make as much code as possible completely independent of the Android API, and then use "clean" unit tests that can run on any JVM. These tests are the fastest, and it helps to save code that does not need Android porting.
  • Unit tests with Robolectric support. Where my code has only slight dependencies on the Android APIs that can be satisfied with Robolectric shadows, I test it with Robolectric. Robolectric has a bit more time to set up compared to pure tests, but it's still faster than starting / running on the emulator.
  • Android framework. Where Robolectric doesn't cut it - either because the shadows do not exist, or because I use the Android API heavily (and therefore want to test against Real Thing) - I write a test that runs on the emulator / device using the default.

The tier point is to simplify the work as much as possible, which speeds up the work of the complete package and helps promote cleaner code.

+92
Feb 22 '13 at 9:27
source share

I worked on both that I found: -

1) Robolectric does not support API 19, he mentions in his document - http://robolectric.org/eclipse-quick-start/ . This is an excellent disadvantage.

2) Roboelectric start on JVM not on DVM. Therefore, we cannot find out that at this particular time GPS is on or off, etc. We can only convey our predetermined meaning for it.

3) Writing code in Robolectric is complicated than junit especially for a fragment has a lot of difficulties and problems.

4) Robolectric needs an external jar and configuration, and for the junit test we do not need an external library.

5) Robolectric is faster because it runs on the JVM, but this is a drawback too, we cannot see the user interface on our device, which screen code is being executed.

For Android, I like the jUnit test.

+4
Feb 19 '15 at 9:37
source share



All Articles