Android Studio
In the Downloads section you will find ExampleTestProject_AndroidStudio which includes a sample Android Studio project with Robotium tests.
In the Android Studio welcome screen click “Open an existing Android Studio project”. Point to the unpacked ‘ExampleTestProject_AndroidStudio’ folder. Android Studio will open the project.
In the Project window find ‘NotePadTest.java’ in app/src/androidTest/java/com.example.android.notepad/. Right click NotePadTest.java and select ‘Run NotePadTest’ to run the tests on either emulator or device.
Eclipse
In the Downloads section you will find ExampleTestProject_Eclipse_v5.5.1.zip which includes a sample application and an example test project.
In Eclipse, import ExampleTestProject_Eclipse_v5.5.1.zip by clicking on File --> Import --> Existing Project into workspace --> Select archive file --> ExampleTestProject_Eclipse_v5.5.1.zip.
Then you can run these test cases either on the emulator or on device. You right click the test project and select Run As --> Run As Android JUnit Test.
Example of a test case (test case spanning over multiple activities where EditorActivity is the first activity):
public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> {
private Solo solo;
public EditorTest() {
super(EditorActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testPreferenceIsSaved() throws Exception {
solo.clickOnText("More");
solo.clickOnText("Preferences");
solo.clickOnText("Edit File Extensions");
Assert.assertTrue(solo.searchText("rtf"));
solo.clickOnText("txt");
solo.clearEditText(2);
solo.enterText(2, "robotium");
solo.clickOnButton("Save");
solo.goBack();
solo.clickOnText("Edit File Extensions");
Assert.assertTrue(solo.searchText("application/robotium"));
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}