安卓自動化測試:Robotium(三)批量運行測試代碼

來源:互聯網
上載者:User

標籤:shell   from   str   生產   common   amp   sts   record   命名   

1、JUnit的TestSuite可以集中存放測試類別,並批量運行測試類別中的測試案例,源碼如下:
package com.coolwi.km.user.testsuites;
import com.coolwi.km.user.testcase.MyCardRecord;
import com.coolwi.km.user.testcase.MyCardUserTestcase1;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestSuite;
//import junit.sampling.*;
public class TestAll {
public static Test suite()
{
TestSuite suite = new TestSuite("All tests from part1");//表明這個標識性東西
suite.addTestSuite(MyCardRecord.class);
suite.addTestSuite(MyCardUserTestcase1.class);
//suite.addTest(new TTmmTest("testHelloworld"));//這裡可以添加單個的測試方法
return suite;
}
}
舉個栗子:可以建立testsuites來存放所有的testsuit,在這個包下建立一個LoginSuit,然後編寫Login_1、Login_2、Login_3,便可運行登入的測試案例
2、選擇使用Android Junit Test 運行 TestAll ,便可批量運行選中的所有測試案例
3、生產JUnit 格式的report
a、匯入(一)中的jar包
b、在runner包下建立一個Runner,命名為CommonRunner,讓該Runner繼承JUnitReportTestRunner,在AndroidManifest.xml中聲明該Runner
<instrumentation
// android:name="com.zutubi.android.junitreport.JUnitReportTestRunner"
android:name="com.coolwi.km.user.runner.CommonRunner"
android:targetPackage="com.coolwi.km.user" />
c、更新第一步的類為TestAll1,繼承 CommonRunner,運行TestAll1
4、匯出測試案例
adb pull /data/data/com.xxx.xxx/files/junit-report.xml
a、adb shell 進入手機,並cd (確保手機被root)
b、su 切換到 root身份
c、用rm -f junit-report.xml確保手機內沒有該檔案,然後運行指令碼
PS:可能運行指令碼後沒有查看到報告,原因是該檔案夾沒有寫的許可權,此時需要 chmod該檔案夾,再運行指令碼
cd /data
chmod -R 777 /data
cd /data/data
chmod -R 777 /data/data

安卓自動化測試: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.