Fandom

Android Wiki

Robotium

220pages on
this wiki
Add New Page
Comments0 Share

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 Edit

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 application15:56

Creating a Robotium test project for an Android application.

ActivityInstrumentationTestCase2Edit

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.

APIEdit

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 executionEdit

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

ExampleEdit

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.