Automated UI testing for Android applications with Robotium

How to Use Xcode to Build IPA

Automatic UI testing helps to keep the quality of your software high and helps you notice if your code changes affect the implementation of the actual use cases. When you are creating Android applications you would like to be able to test them without the help of many human testers. Human testing of UI of the same application on multiple devices is a waste of time, so you want to eliminate it through automation, like you would do it with Selenium for web application. For Android applications there is a similar tool for testing called Robotium. It is a UI testing tool which simulates touching, clicks, typing, and other users’ actions relevant for Android applications. Writing tests using Robotium is very easy as you can see from below.

Bitbar, the company I work for, has created a Continuous Integration environment with automated UI testing for Android applications. Here are some benefits of using it:

    • Automated execution of UI tests (created in Robotium) on each commit.
    • Testing against many configurations, real devices and targets that emulate real devices
    • Visual presentation of test results in human friendly form
    • Screen shots from the UI testing process, so you can see how your application looks on real devices

As an example of using Robotium I show you how to create tests for one of my Android applications used for monitoring of Hudson’s jobs.

Create Android Test Project:

If you are Eclipse user (and your Eclipse has ADT plugin) you should open project which you want to test  and then chose menu File → New → (Other → Android) → Android Test Project. Create test project for existing Android project. To run it select Run As –> Run As Android JUnit Test.
Other non-Eclipse) developers should use android tool from Android SDK. (In this example I use it in test project directory) :

android create test-project -p . -m ../HudsonMonitor
-n HudsonMonitorTest

– after –p put the path to your test project directory
– after -m put the path to project which you will be testing
– after –n put the name of test project
To build it you should use ant like ant debug or ant release (for release) but remember to add robotium.jar file to this project’s libs directory (if you don’t do this you will have NoClassDefFoundError for class.
To install the application and the tests on emulator or device use:

adb -s emulator-5554 install -r binHudsonMonitor-debug.apk
adb -s emulator-5554 install -r binhudson_monitor_test-debug.apk

To run the tests:

adb shell am instrument

but remember to unlock emulator before you run the tests.

Creating Test Cases:

Ok, so now we should create class which will be implementing a test case. The only thing that we should know about the tested project is the name of the package and the name of the main class. Test case class in our test project looks like this:

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;

public class HudsonMonitorTest extends ActivityInstrumentationTestCase2 {

  private Solo solo; // this is Robotium class used to support test cases that span over multiple activities.

  public HudsonMonitorTest() {
     super("", HudsonMonitor.class);

  public void setUp() throws Exception {
     solo = new Solo(getInstrumentation(), getActivity()); //takes in the instrumentation and the start activity.

  public void tearDown() throws Exception {
     try {
     } catch (Throwable e) {



Our application has four Tabs: “Statistic”, “Details”, “Webpage” and “Configuration”. One of ways to choose one of them is to click an element with text, for example choose “Configuration”:


The first test checks “adding new Hudson” use case. On configuration screen we have two EditTexts and a ListView of monitored Hudson’s jobs. In first EditText the test should typing feed URL (ex. hudson:8080) for Hudson and in the second its name (e.g. hudson) which will be shown in our app to identify this Hudson instance. In Robotium widgets on the screen are numerated from top to bottom and from left to right and start form 0, so our code for this action is:

// 0 because it is the first EditText on screen
solo.enterText(0, "hudson:8080");
// 1 because it is the second
solo.enterText(1, "hudson");

To add this Hudson to HudsonMonitor application we should click on ImageButton with plus sign . It is first ImageButton from top and left so it has number 0:

// for ImageButton use only clickOnImageButton method,
// but for simple button use clickOnButton

Then we must check whether the item with this Hudson feed URL has been added to the list:

boolean expected = true;
boolean actual = solo.searchText("(http://hudson:8080)");
assertEquals("Can't add new Hudson Instance", expected, actual);

The entire source code of this test is as follows:

public void testAddNewHudson() throws Exception {
solo.enterText(0, "hudson:8080");
solo.enterText(1, "hudson");
boolean expected = true;
boolean actual = solo.searchText("(http://hudson:8080)");
assertEquals("Can't add new Hudson Instance", expected, actual);

Second test should check details of activity which has a Spinner and a table with details about builds. To choose an item from Spinner we can use the following method:

solo.pressSpinnerItem(0, 1);

This method will only select one item from the Spinner, When we need check something on Spinner item’s list we should use the following code:


To use this code we must import R from tested Project (HudsonMonitor). Using method …OnView we can test every widget on the screen, but we must have more information about project which we are testing.


Robotium is very easy to use and can help to keep very high quality of your software throughout the project lifecycle. Bitbar has created an automated build and test environment for Android application developers who can build and test their applications on many configurations, real devices and targets that emulate real world devices.
In our Continuous Integration service for Android applications the developer can automate his testing process for multiple emulators of the real android devices.
You can specify your Android targets and all parameters for emulators which will be used for testing your application.

For every developer’s code submission (commit or push) our system builds it and tests the application automatically. You can also see the test results in a human friendly form, including screenshots from testing process for each emulator.

If you have problems or questions about Robotium please put it in the blog post comments and I will try to help you.
If you are interested in our automated build and test System for Android applications, please contact us at info(at)

Manifesto: Everything about Mobile DevOps

Learn how to properly adopt DevOps approach for your mobile team and get the most out of it.


  • Jouko Kaasila

    This blog post is referred by

    Please check the blog post for details:

  • Pingback: Android UI Design Patterns & Best Practices – part 1 - Bitbar()

  • Deepak


    Can you please let me know that do we require Java programming in this tool or without that we can do testing on application.


  • Radek Męzik

    Please go to Help page, you will find there step by step tutorials which show you how to record tests without knowing Java, but some basic knowledge could be very useful.

    Best regards,

  • Pingback: Weekly Article Links #4 « Practical Tips on Software Testing()

  • Adarsh


    I am involved in the testing of an Internet TV which is based on Android OS.
    I want to know if there is any way to to test the UI parts(like buttons and their expected functionality available in the TV)?
    We don’t get any source code for the software but we get a final builded and integrated image of the software which we used to flash on the TV board for testing.For taking any logs we use HyperTerminal in windows.

    Please help if I can use Robotium to test the various Android applications present in the TV product.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.