Android Wiki

Welcome to the Android Wiki! Before getting started, please read the wiki's rules and editing manual! If you need help about the wiki, please contact the staff members! If you want to meet our community, go to the discussions page and our Discord server! And don't forget to follow us on Twitter/X and YouTube!

DiscordSocial TwitterSocial YouTubeSocial

READ MORE

Android Wiki
Advertisement

Robotium is an open-source Android test automation framework which supports native and was developed to make it easy to write user interface tests for Android native and hybrid applications. It is an extension of the Android test framework. Robotium tests inherit from ActivityInstrumentationTestCase2 and allows to create test cases across Android activities.

The official documentation provided by Google is available here .

This article should help you to start using Robotium and write your first integration test for Android app. Enjoy the guide.

Setup

Robotium setup is very easy and quick. The only thing you need is to add the Robotium jar to the build path of your test project. You can do this simply in Eclipse by right clicking on the test project --> Properties --> Java Build Path --> Add (external) Jar.

If it seems to hard, watch the video below.

Creating_a_Robotium_test_project_for_an_Android_application.

Creating a Robotium test project for an Android application.

ActivityInstrumentationTestCase2

ActivityInstrumentationTestCase2 is the class which every test class inherits from. It contains two methods that are required to run tests:

Setup





Both methods can be overridden inside the test class to ie. turn wifi on/off, handle dialogs, set up some initial values, or close all activities.

API

Robotium provides the class called Solo which is the main class for development of Robotium tests. Solo provides methods to call Android UI and has full support for:

  • Views
  • WebViews
  • Activities
  • Dialogs
  • Menus and Context Menus

It contains methods to simulate different gestures, like:

  • clicking
  • swiping
  • scrolling
  • pinching
  • rotating device

List of methods provided by Solo you can find here .

Tests execution

You can run Robotium tests from Eclipse or using command line. 

To run test using Eclipse, only you have to do is to right-click the test class you want to execute --> Run-As -->  Android JUnit Test.

If you prefer to use command line, here is the command you can use:

adb shell am instrument -w example.android.test.name/android.test.InstrumentationTestRunner

Example

Test which clicks on menu button with specific text, then clicks first element from list and checks if dialog with correct text opens. At the end test navigates to initial activity.

Screen Shot 2014-10-31 at 3.35.14 PM
Advertisement