Android test---robotium----簡單例子

來源:互聯網
上載者:User

標籤:

1.首先建立一個要被測試的工程,命名為”robotium“;一個很簡單的Android 應用程式;首頁面只有個 TextView 控制項;

2. 在建一個用於測試的工程 ,命名為”robotiumTestCase" ;檢查被測apk的頁面是否有某個字 如“hello ” “world” 等;

2.1 選擇file-》new--》project----》Android test project

2.2 輸入測試工程的名字 robotiumTestCase

2.3 選擇被測試的項目 “robotium”  然後點擊finish 完成測試專案的建立;

2.4 建立一個用於測試的測試案例 。在剛剛建立的工程 右鍵 選擇---new ---->class ------》finish

3. 匯入robotium ;

3.1 將下載的 robotium-solo-xxx.jar 儲存到測試工程的根目錄下的libs 中,如果沒有可以新建立一個libs 檔案夾;

 

3.2  把robotium-solo-xxx.jar 加入到測試工程的引用路徑中來;右鍵測試工程----選擇----》build path----》configure build;

3.3 在彈出Java build path 的對話方塊中選擇 libraries 的那個tab選項------》點擊 add external JARS。。。那個按鈕 添加剛剛在步驟3.1 中的儲存的robotium-solo-xxx.jar

3.4 同樣的在Java build path 的對話方塊中選擇 orderand  export的那個tab選項----》選擇robotium-solo-xxx.jar 並且讓其置頂;

具體中步驟

4.添加了開原庫 robotium-solo-xxx.jar ,接下來就是編寫測試案例了,檢查一下首頁面是否有某個字;

代碼如下:

package com.example.robotium.test;import com.robotium.solo.Solo;import android.test.ActivityInstrumentationTestCase2; public class test extends ActivityInstrumentationTestCase2 {    private Solo solo;     public test()  throws Exception {        super(Class.forName("com.example.robotium.MainActivity"));        // TODO Auto-generated constructor stub    }     @Override       protected  void setUp()  throws Exception {          solo =  new Solo(getInstrumentation(),getActivity());      }         @Override       protected  void tearDown()  throws Exception {          solo.finishOpenedActivities();      }            public void test測試案例() throws Exception{         boolean expected =true;         boolean actual =solo.searchText("debbie")&&solo.searchText("xie");          assertEquals("debbie is are not found", expected, actual);     }    }

5. 最後就是運行我們的測試工程了。右鍵測試工程,選擇run as -----> andriod junit test .執行完成後,將看到一個測試結果;

看到的結果是錯誤的 ;因為被測試的apk 只有hello world 這些字 而沒有“Debbie” or “xie"

 

 

Android test---robotium----簡單例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.