-1

我是使用 Robotium 进行 android 应用程序测试的新手。你能指导我如何开始吗?你也可以请给我一些书籍,视频或链接。

我在谷歌上找到了使用 Robotium 进行测试的入门

我从那里下载了记事本项目并运行到 Eclipse,但我无法理解诸如testAddNote()testEditNote()testRemoveNote() 之类的方法是如何调用的。

NotePadTest.class

 public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList>{

private Solo solo;

public NotePadTest() {
    super(NotesList.class);

}

@Override
public void setUp() throws Exception {
    //setUp() is run before a test case is started. 
    //This is where the solo object is created.
    solo = new Solo(getInstrumentation(), getActivity());
}

@Override
public void tearDown() throws Exception {
    //tearDown() is run after a test case has finished. 
    //finishOpenedActivities() will finish all the activities that have been opened during the test execution.
    solo.finishOpenedActivities();
}


public void testAddNote() throws Exception {
     
    solo.clickOnMenuItem("Add note");
    //Assert that NoteEditor activity is opened
    solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor"); 
    //In text field 0, add Note 1
    solo.enterText(0, "Note 1");
    solo.goBack(); 
    //Clicks on menu item
    solo.clickOnMenuItem("Add note");
    //In text field 0, add Note 2
    solo.enterText(0, "Note 2");
    //Go back to first activity named "NotesList"
    solo.goBackToActivity("NotesList"); 
    //Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
    solo.takeScreenshot();
    boolean expected = true;
    boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
    //Assert that Note 1 & Note 2 are found
    assertEquals("Note 1 and/or Note 2 are not found", expected, actual); 

}

public void testEditNote() throws Exception {
    // Click on the second list line
    solo.clickInList(2); 
    // Change orientation of activity
    solo.setActivityOrientation(Solo.LANDSCAPE);
    // Change title
    solo.clickOnMenuItem("Edit title");
    //In first text field (0), add test
    solo.enterText(0, " test");  
    solo.goBack();
    boolean expected = true;
    // (Regexp) case insensitive
    boolean actual = solo.waitForText("(?i).*?note 1 test"); 
    //Assert that Note 1 test is found
    assertEquals("Note 1 test is not found", expected, actual); 

}

public void testRemoveNote() throws Exception {
    //(Regexp) case insensitive/text that contains "test"
    solo.clickOnText("(?i).*?test.*");
    //Delete Note 1 test
    solo.clickOnMenuItem("Delete");
    //Note 1 test & Note 2 should not be found
    boolean expected = false;   
    boolean actual = solo.searchText("Note 1 test");
    //Assert that Note 1 test is not found
    assertEquals("Note 1 Test is found", expected, actual);  
    solo.clickLongOnText("Note 2");
    //Clicks on Delete in the context menu
    solo.clickOnText("Delete");  
    actual = solo.searchText("Note 2");
    //Assert that Note 2 is not found
    assertEquals("Note 2 is found", expected, actual);  
}
}

还有一件事我也不知道关于 web 应用程序的 selenium。

- 谢谢,

拉胡尔帕特尔

4

1 回答 1

1

在此处找到的 Robotium 入门页面中,他们指出:

...您可以在模拟器或设备上运行这些测试用例。右键单击测试项目并选择 Run As --> Run As Android JUnit Test。

它将运行 NotePadTest 类中的所有测试方法。请记住,您需要在您的模拟器/设备上运行应用程序的实例,但运行测试类应该将其重新部署到您的目标。

我不使用 eclipse,但在 IntelliJ 中,它们还允许您为各个测试方法创建运行配置,以独立于类中的其他测试运行它们。我想如果它是你感兴趣的东西,那么在 eclipse 中也有一个等价物。

至于 selenium,你可以在这里找到他们的网站和文档。他们还有一个用于在 Android 浏览器中测试页面的驱动程序。StackOverflow 并不是解决诸如“你能教我如何使用它”之类的一般性问题的地方,但如果你尝试它并有关于让它工作或执行一些操作的具体问题,我相信社区会很高兴回答他们!

于 2013-02-08T14:57:48.653 回答