How to Use Robotium Testing Tool for Android Apps

15 May 2017
How to Use Robotium Testing Tool for Android Apps
 Robotium Testing Tool
Posted by Root Info Solutions

User Experience is paramount to the success of a mobile app and related business endeavor. Unfortunately, there are no short-cuts to it. It demands a cohesive effort from all quadrants. Every cohort, be it of UI-UX designers, mobile app developers and the quality analysts have to give their best. Fortunately, there are some amazing tools that mobile app development constituents must be acquainted with.

See how Robotium makes a difference to app delivery and quality.

What is Robotium?

Well, it?s an open source library with extended JUnit aimed at building black-box test cases required to test the functionality of Android APIs. The test framework works for both native and cross-platform app types.  You can write function, system and acceptance test scenarios, and test the source code in a quick and easy manner.

How to Use Robotium

Step 1. Setting up Gradle in Robotium: Attempt either of the methods.

Add the Gradle Dependency in app.gradle then Sync the gradle.
dependencies {
?androidTestCompile '


(b) Download Robotium Jar from Below Link, add it to the Library Folder in Gradle. Add ?compile files('libs/robotium-solo-5.6.3.jar')?, in app.gradle.

Where Do We Use Robotium in Android Studio

We create Robotium Test cases inside Android Test Class folder which gets generated automatically at the time of project creation.


Step 2: How To Set Up Robotium in ?Android Test Class?

Robotium is an extension of the Android test framework and is created to make it easy to write user interface tests for Android applications. ?Robotium tests inherit fromActivityInstrumentationTestCase2?  allows you to define test cases across Android activities. Here is how to write a user interface test case.

How to use robotium

Solo -:

The main class for testing with Robotium is Solo. Solo is initialized with the instrumentation of the test case.

SetUp() and tearDown() -:

The methods setUp() and tearDown() run before and after each test case. At the end of a test run, the tearDown() method is called to close all activities and to clean up the Solo object.

Step 3: How to Code Using Robotium in Android Test Class

a. Login and Logout test case using Robotium

robotium login and logout testing

b. Coding example of Swipe Screen Left to Right

 Coding example of Swipe Screen Left to Right

Step 4: How to Run Robotium in Android Studio

a. Click on ?App? and ?Edit Configurations? as pointed out in the below image.

How to run robotium

b. Click on ?Plus? icon and then click on ?Android Instrumentation? test. Provide ?test name', select ?app in module? and click ?OK?.

Android Instrumentation? test

c. Click on ?Configuration? and select ?Test Name? and then run the program.


Methods of Robotium

robotium method

Benefits of Robotium

Powerful tests cases can be created in a quick and easy manner.

  • APIs are offered so that direct interaction can be done with UI controls in the application
  • Android 1.6, as well as above versions, are officially supported by it
  • Robotium does not modify the Android platform
  • Command prompt may be used for the execution of the test
  • Smooth integration of the framework may be done with Ant or Maven, helping in the addition of the framework to build the automation process of the project

Limitations of Robotium

  • No support for flash & web applications
  • Test execution on one device at a time
  • Inability of handling different Applications in one test    
  • No support for cross-platform (iOS, Windows etc.)  

Here is a List of Related Testing Tools

  • MonkeyRunner
  • Appium

Compare with MonkeyRunner

  • Robotium test cases are in Java and MonkeyRunner test cases are in python.
  • MonkeyRunner necessitates writing scripts for each device whereas in Robotium QAs don?t need to do so. So Robotium is a big time saver.
  • In a case of MonkeyRunner, a test has to be adjusted each time the user interface of a test build undergoes a change, whereas in Robotium there are no such demands.
  • Robotium syncs easily with Maven, Gradle or Ant for the execution of tests.

Compare with Appium

  • Robotium supports Android only whereas Appium supports iOS and Firefox OS along with Android.  
  • Robotium is limited to mobile apps for Android whereas Appium can be used to test mobile web apps along with the native and hybrid mobile apps.
mobile app development company