推荐一个Android下的自动测试框架robotium

Robotium 是一个Android环境下的自动测试框架。Robotium 可以简单的编写功能强大且健壮的自动黑盒测试脚本。有点类似windows平台下的QTP。


public class EditorTest extends
                ActivityInstrumentationTestCase2 {

  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();
  }
}



https://code.google.com/p/robotium/

你可能感兴趣的:(Android)