當前位置:編程學習大全網 - 源碼下載 - 如何根據單元測試xml結果 生成最終的測試報告

如何根據單元測試xml結果 生成最終的測試報告

使用robotium進行Android應用進行自動化測試,之前用TMTS框架,但收集到的單元測試結果常常會少掉壹些用例集。。窮則思變,Android的測試框架主要是通過InstrumentationTestRunner對被測應用進行控制與執行,因此可以對InstrumentationTestRunner進行擴展以完成測試結果收集,然後通過jenkins的Publish JUnit test result report插件得到結果報告。

1.新建壹個java package,新建壹個java類

源碼來自開源項目:/p/nbandroid-utils/

源碼中生成的TEST-all.xml結果文件位於/data/data/com.example/files目錄下,要導出結果文件的話,需要手機擁有root權限,比較麻煩,因此下面修改了文件存放路徑,有SD卡則文件位於SD卡的/robotium目錄下

代碼貼不下,詳細代碼請見.example" />

修改為:

[html] view plaincopy

<instrumentation

android:name="com.example.test.instrumentation.InstrumentationTestRunner"

android:targetPackage="com.example" />

3.修改Run Configurations

右鍵測試工程>Run as >Run Configurations

在Test欄中,勾選Run all tests in the selected project,or package

這樣每次在Eclipse中運行時才會使用新的InstrumentationTestRunner

在Instrumentation runner處下拉選擇新寫的InstrumentationTestRunner

點擊Apply完成設置

4.命令行下運行測試用例

Running all tests: adb shell am instrument -w com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner

Running a single testcase: adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner

Running multiple tests: adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner

命令行下運行測試用例與平時壹樣,只要將原來的InstrumentationTestRunner換成新的InstrumentationTestRunner就行,

需要註意的是,由於每次命令行執行完畢,都會覆蓋原有的TEST-all.xml文件,即如果采用Running a single testcase方式運行多個測試用例集,則最後結果只會記錄最後壹個用例集,因此建議采用Running multiple tests方式

5.運行完成後將手機中的文件導出

adb -s $ANDROID_AVD_DEVICE pull /mnt/sdcard/rototium/TEST-all.xml

其中$ANDROID_AVD_DEVICE為參數化的手機序列號

6.在jenkins中任務構建完成後即可使用Publish JUnit test result report插件分析得出單元測試報告

  • 上一篇:怎麽在網頁中加入百度地圖怎麽在網頁中加入百度地圖導航
  • 下一篇:作為果凍行業的後起之秀,喜之郎公司是如何成為果凍市場的龍頭老大的
  • copyright 2024編程學習大全網