Contributed by: Prachi Pawnaskar (Software Engineer, Clarice Technologies)

Prachi has been with Clarice Technologies for about 2.5 years and worked for a major time with Tan ‘n’ Tap as a software engineer. She is currently working on web apps for remote management of storage devices based on WBEM. She has contributed a great deal in the design and automation of testcases for Android apps, over the air updates solutions for Android tablets and worked heavily on other Android devices.


Once your Android app is out in the market, you have no control over the habitat it is going to live in and run. There are going to be a multitude of possible device configurations that would be host to your app – with different screen sizes, different resolutions, varied battery performance, with/without a camera, with/without GPS and with/without motion sensors.

Testing your android app is a challenge due to the different configurations. I’ve tried to outline the various things you should take into consideration while testing your app.

What to test?

1.    Change in orientation of device – Landscape Portrait

  • Test to check that the screen is re-drawn correctly after orientation change
  • Test whether the application maintains its state after orientation change

2.    Change in configuration

Does your app correctly handle changes in configuration?

  • Test by changing the language of the phone/tablet from the settings UI
  • Test by changing the system keyboard
  • Test by changing the system time for time/clock related apps like Reminder, To-do, Calendar, etc.

3.    Dependency on external resources

Your app may depend on external resources like Wi-Fi, Camera, SMS, Sensors, etc. In that case you should test to see what happens when the resource/s are not available.

  • If your app requires network access , then it should notify user if access is unavailable, or disable network features until network is available

4.      Intent Handling and Filtering

Intents are the means for your app to interact and communicate with the rest of the system and to react to events in system.

  • Test that your app listens and reacts to the right set of intents broadcasted in the system. You may not want to miss out on some important intents like “BATTERY_LOW” and “WI-FI AVAILABLE”
  • Test the intent handling logic
  • Test to see that your app broadcasts correct intents when needed. E.g.: If your app is meant to be a replacement for a system app, make sure that all the intents handled by the system app are implemented in your app as well

5.    Services

A Service in Android is an application component that can perform long-running operations in the background and does not provide a user interface.

If your app contains a Service component, then you may want to test its lifecycle to:

  • Ensure that your app elegantly handles the case where the service was killed /stopped for some reason
  • Test that your service is not running after its job is done. The service should be stopped if it is not needed anymore
  • Test that your Service correctly handles multiple calls from Context.startService(). Only the first call triggers Service.onCreate(), but all other calls should trigger a call to Service.onStartCommand()

6.      Performance

Is your app slowing down the system?

  • Check if there is excessive logging as excess logging slows down the app
  • Check if your app is using large amounts of memory

A tool that can be used to profile performance of your app is Traceview.

7.      Adhering to Guidelines and Best Practices

Ensure that your app follows UI guidelines and best practices by Google:


How to test?

  1. Manual Testing
  2. Automated Testing

I am listing a few ways of automating tests for your Android App.

1.    JUnit

Since the language used for coding Android Apps is Java, one can always use the standard JUnit framework for testing. You can use the JUnit TestCase class to do unit testing on a class that doesn’t call Android APIs.

2.    Android’s Testing Framework and API

The Android testing API is based on the JUnit API and extended with an instrumentation framework and Android-specific testing classes. It consists of following main components:

  • Android Specific testing classes: AndroidTestCase is the base test class, which you can use to test Android-dependent objects. Besides providing the JUnit framework, AndroidTestCase offers Android-specific setup, teardown and helper methods. Apart from this Android also provides component specific classes for testing Activity, Service and Content Providers like ActivityTestCase and ServiceTestCase
  • Assertions: Android also provides a class of assertions that extend the possible types of comparisons and another class of assertions for testing UI related assertions
  • Instrumentation: Android instrumentation is a set of control methods or “hooks” in the Android system. These hooks control an Android component independently of its normal lifecycle. With Android instrumentation, you can invoke callback methods in your test code that allow you to run through the lifecycle of a component step by step. Instrumentation also allows you to trigger click, tap or touch events
  • Mock object classes: To facilitate dependency injection in testing, Android provides classes that create mock system objects such as Context, ContentProvider, ContentResolver, Service and Intent. A detailed documentation of the usage of this API can be found here:

3.    MonkeyRunner

The monkeyrunner tool is an API and execution environment for test programs. The API includes functions for connecting to a device, installing and uninstalling packages, taking screenshots, comparing two images and running a test package against an application

4.      Robotuim

Robotium is a test framework automatic black-box test case for Android applications. Robotium is basically used for GUI testing. I found Robotium useful for writing quick UI black-box tests, in cases where the app UI is simple, light and consists of fewer UI controls. Things start becoming a bit complicated when the UI is heavy, has a lot of hidden/invisible components or widgets are dynamically added to the screen. I think in case of complex and heavy UI, it is better to use Android testing and Instrumentation framework. It gives a lot more control. Robotium tutorials can be found here:

I look forward to your comments…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>