Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android unit test case automation: Robolectric library vs Android Testing framework

Wondering which one is the better choice to write unit test cases for android apps and libraries: Using Robolectric library or sticking with Android Testing framework. I want to run test suite at commandline and want it be independent of need of configuring emulator or letting a device attached with build machine. Does anyone of you run a comparative analysis on both of these or something better? Your experiences will be great help me to decide on the better solution.

like image 283
bianca Avatar asked Feb 19 '13 03:02

bianca


People also ask

Which framework is more suitable for unit testing Android?

In general, Appium and Calabash are good cross-platform frameworks in testing both your Android and iOS versions at the same time. Espresso is a good choice if you are purely testing Android apps. Therefore, think about your testing need – functional testing, compatibility testing, UI testing, etc.

What are the types of automated unit tests in android?

In Android, there are two test types. The tests running on our local Java Virtual Machine (JVM). The tests running on our Android platform (in which we need devices or emulator).

What is an Android testing framework?

Android App Development for Beginners The Android framework includes an integrated testing framework that helps you test all aspects of your application and the SDK tools include tools for setting up and running test applications.

How can write unit test cases for activity in Android?

unit tests can be written under test java package, and instrumental tests can be written under androidTest package. You can then access UI widgets using Espresso ViewMatchers and then you can apply actions on them using ViewActions . Check documentation for further help. Show activity on this post.


1 Answers

I use a tiered system, where I prefer earlier tiers where possible:

  1. Pure unit tests. I try to make as much code as possible fully independent of Android APIs, and then use "pure" unit tests which can run on any JVM. These tests are the fastest, and it helps keep code that has no need to be Android-specific portable.
  2. Robolectric-supported unit tests. Where my code has only small dependencies on Android APIs, that can be satisfied by Robolectric shadows, I test it with Robolectric. There is a little more setup time for Robolectric compared to pure tests, but it's still faster than starting/running on an emulator.
  3. Android framework tests. Where Robolectric doesn't cut it - either because the shadows don't exist, or because I'm heavily using Android APIs (and therefore want to test against the Real Thing) - I write test that run on the emulator/device with the default framework.

The point of the tiers is to keep things as simple as possible, which keeps the full suite faster and helps promote cleaner code.

like image 98
Jason Sankey Avatar answered Oct 18 '22 17:10

Jason Sankey