Robotium 是一个Android环境下的自动测试框架。Robotium 可以简单的编写功能强大且健壮的自动黑盒测试脚本。有点类似windows平台下的QTP。
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.sendKey(Solo.MENU);
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();
}
}