• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • Android的自動測試研究--Robotium

    發表于:2013-05-29來源:Csdn作者:xyz_lmn點擊數: 標簽:Android
    Robotium的jar包和程序例子地址: http://code.google.com/p/robotium/ Android的自動測試研究,我相信有很多在接觸android的人當中,

      Robotium的jar包和程序例子地址:

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

      Android的自動測試研究,我相信有很多在接觸android的人當中,也在網上不斷的搜索和研究究竟有沒有能應用android自動化測試手段,我也是如此,經過一番尋找研究有幸接觸到了Robotium這個東東,他能一定程度上給我們一些想要的效果,現將小試牛刀的一些東東分享出來.

      Robotium is a test framework created to make it easy to write powerful and robust automatic black-box test cases for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.

      Robotium has full support for Activities, Dialogs, Toasts, Menus and Context Menus.

      上邊的一段英文是官方一段文字,也就是我們利用Robotium可以做一些對android的一些自動化測試工作,并且他是可跨越多個Activites,且容易寫一些測試case的,一定程度上能做一些黑盒的自動化工作,在這里先簡單跑一個notpad的例子,看看跑起來的效果是什么樣的,后續繼續做些更詳細的。

      一、確保環境

      1.已經安裝eclipse

      2.Eclipse已經配置好android相關環境

      3.存在已經創建模擬器

      二、步驟

      1.啟動Eclipse執行 New --> Project --> Android Project --> Create Project from existing sample --> NotePad將自帶的例子導入進來.

      2.在官方down欄下下載三個文件,兩個是所需要的jar包,另一個是notepad的測試例子

      (當前最新的是2.5Featured,這里就不提供下載連接了版本更新的還是比較快的)

      3.然后執行File --> Import --> Existing Project into workspace --> Select archive file --> ExampleTestProject_v2.5.zip將例子導入進來(如果錯誤可能需要你在這個項目上將剛才說需要的兩個jar導入project --> Properties --> Java Build Path --> Add (external) Jar)

      4.右鍵選擇剛才導入的test例子執行Run As --> Run As Android JUnit Test.

      如果沒有意外的話會自動啟動模擬器并且運行起來了.

      http://www.devdiv.com/data/attachment/album/201110/11/155452zmygarwywa9e9zwv.png

      再欣賞一下代碼:

      public class NotePadTest extends ActivityInstrumentationTestCase2{

      private Solo solo;

      public NotePadTest() {

      super("com.example.android.notepad", NotesList.class);

      }

      public void setUp() throws Exception {

      solo = new Solo(getInstrumentation(), getActivity());

      }

      @Smoke

      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");

      // solo.

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

      }

      @Smoke

      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.goBackToActivity("NotesList");

      boolean expected = true;

      // (Regexp) case insensitive

      boolean actual = solo.searchText("(?i).*?note 1 test");

      //Assert that Note 1 test is found

      assertEquals("Note 1 test is not found", expected, actual);

      }

      @Smoke

      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");

    原文轉自:http://blog.csdn.net/xyz_lmn/article/details/6899905

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>