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.
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.
ActivityInstrumentationTestCase2 is the class which every test class inherits from. It contains two methods that are required to run tests:
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.
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:
- Menus and Context Menus
It contains methods to simulate different gestures, like:
- rotating device
List of methods provided by Solo you can find here .
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
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.