1. 程式人生 > >Monkey測試手機BUG重現及解決方法

Monkey測試手機BUG重現及解決方法

一次 重新開始 ive system androi 測試工具 jar 子郵件 anr

1.1 Monkey測試簡介

Monkey測試是Android平臺自動化測試的一種手段,通過Monkey程序模擬用戶觸摸屏幕、滑動Trackball、按鍵等操作來對設備上的程序進行壓力測試,檢測程序多久的時間會發生異常。

1.2 Monkey程序介紹
1) Monkey程序由Android系統自帶,使用Java語言寫成,在Android文件系統中的存放路徑是:/system/framework/monkey.jar;

2) Monkey.jar程序是由一個名為“monkey”的Shell腳本來啟動執行,shell腳本在Android文件系統中的存放路徑 是:/system/bin/monkey;這樣就可以通過在CMD窗口中執行: adb shell monkey {+命令參數}來進行Monkey測試了。

1.3 Monkey命令的簡單幫助
要獲取Monkey命令自帶的簡單幫助,在CMD中執行命令:
adb shell monkey –help

1.4 Monkey命令參數介紹
可參考MTK相關文檔。

Android_Monkey_Test_SOP.pdf

Monkey_Test_SOP_Customer_MT6572_4.x .pdf

1.5 Monkey測試步驟
步驟1:下載user版本後手動導入APR工具。

步驟2:導入完畢後重啟手機,連接usb線,運行logServerInstall.bat。

步驟3:運行後手機會自動重啟,重啟完畢後手機端鍵入*#*#2012#*#*,能夠進入對應界面即為apr安裝成功。

步驟4:手機連接電腦,開啟adb:鍵入adb shell ps logserver,查詢logserver的PID值,然後鍵入adb shell kill PID(logserver PID)。

步驟5:再次鍵入adb shell ps logserver查看logserser已被kill掉。

步驟6:手機連接電腦,開啟USB存儲,在手機內存(或SD卡)中,新建一個名為whitelist的txt文件,該文件中輸入想跑的模塊名,每個模塊輸入後回車輸入下一個,若對模塊名稱不熟悉可參考monkey測試報告,內有模塊排練信息。

例如:com.chinamobile.cmccwifi

com.cmcc.mobilevideo

com.hisunflytone.android

步驟7:上一步完成後,手機端進入對應的apk模塊,如:whitelist中想跑新浪微薄,uc瀏覽器的話,手機端分別進入這些應用,把首次使用提示框點掉,記得勾選上永遠不提示的選項以免跑monkey無法正常測試。

步驟8:手機連接電腦,打開adb。

步驟9:鍵入adb shell,回車後鍵入

monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 200000 >/mnt/sdcard/Stability_base.txt

步驟10:此時,既能正常開始monkey,並記錄開始時間。

步驟11:Monkey結束後手機連接電腦,運行getDataLog.bat,生成 datalog。連接usb存儲,在是手機上找到Stability_base.txt文件,查看最後修改時間,該時間即為monkey運行最後結束時間。

1.6 Monkey測試問題分析及處理技巧
Monkey測試主要是測試負責,研發這邊配合測試進行問題復現及給出測試建議,重點工作還是monkey問題分析,包括凍屏、死機重啟、crash等。由於這類問題分析起來比較麻煩,所以一般如果沒有相關分析經驗可以先定位問題,準備好相關的log配合MTK分析或者找部門內部有相關經驗的研發人員配合分析。

1.7 Monkey測試註意事項
註意事項:

1. 測試關閉所有網絡開關(wifi及數據連接)

2. 開啟安全設置下的未知來源

3. 手機連接電源充電

4. 若有有關於音頻的模塊,請插入耳機避免影響其他同事

5. 若測試信息模塊時需要安裝測試工具testwizard.apk,自動生成通話記錄,短信(數量為10)

6. 若測試文件管理器需要在T卡內存放有圖片/音樂/apk/視頻/txt這類文件

7. 測試圖庫是需要T卡內存放100個圖片及視頻的,同樣音樂和視頻播放器也需要存放不少於50個片源

8. 測試電子郵件的需要新建兩個以上的賬戶

9. 測試前運行一遍手機上方帶有的首次提示的說明,如輸入法,文件夾窗口,apk提示語等

10. 若測試時遇到問題想重新開始測試,必須拔掉電板後重新鍵入adb指令重新開始。

1.8 Monkey測試命令
1. 跑ALL apk命令

monkey --throttle 500 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 800 -v -v -v 200000>/mnt/sdcard/Stability_all.txt

2. 跑白名單命令

monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 200000 >/mnt/sdcard/Stability_base.txt

3. 跑黑名單命令

monkey --pkg-blacklist-file /mnt/sdcard/blacklist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 200000 >/mnt/sdcard/Stability_base.txt

1.9 Monkey測試問題分析
Monkey測試log為標準MTK log,常見問題也是以下幾種:Crash、NE、KE、ANR等。

測試前首先關閉MTK log,將sdcard卡和手機內存中的舊的log清理趕緊,最相關幹擾文件一並清理幹凈,否則後期取出log很容易造成困擾。


註意事項:
1)每個模塊使用3臺手機測試,測試完成後恢復出廠設置在測試其他模塊,避免殘留文件影響其他模塊測試結果.

2)測試部分需要資源的模塊,測試前需要先導入資源.
信息:導入500條短信
聯系人:導入500個聯系人
音樂:導入100個歌曲
視頻:導入20個視頻
瀏覽器:插入有錢的SIM卡,開啟數據連接,連接WIfi
FM收音機:插入耳機
Email:登錄郵箱帳號

3)部分模塊第一次進入有使用說明或者協議說明,需要手動點擊完成後在測試.
應用市場:勾選不再提醒,完成所有提示確認
主題:勾選不再提醒,完成所有提示確認
相機:勾選不再提醒,完成所有提示確認
圖庫:勾選不再提醒,完成所有提示確認
......
因為應用太多就不列舉出來了,每個模塊測試前先手動進入查看,完成所有導航在進行測試.


Monkey測試命令

1.
跑ALL APK命令:(>2小時)
monkey --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 30000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑單個APK命令(>6小時):
monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 90000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑單個APK命令(>2小時):
monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 30000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

2.
跑ALL APK命令(>12小時):
monkey --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 180000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑ALL APK命令(>12小時)加入黑名單:
monkey --pkg-blacklist-file /mnt/sdcard/blacklist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 180000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑單個APK命令(>12小時):
monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 180000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt
3.
跑ALL APK命令(>24小時):
monkey --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 360000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑ALL APK命令(>24小時)加入黑名單:
monkey --pkg-blacklist-file /mnt/sdcard/blacklist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 360000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt

跑單個APK命令(>24小時):
monkey --pkg-whitelist-file /mnt/sdcard/whitelist.txt --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000 -v -v -v 360000 1 >> /mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt


註:跑單個APK時一定記住在手機存儲根目錄裏面放一個白名單文件:whitelist.txt,txt文本寫入要測的模塊APK應用的包名即可,表示只跑指定apk,如果是在手機根目錄中放blacklist.txt,填寫相應包名,指跑除blacklist.txt上指定應用的所有應用。Monkey跑完後檢查log裏面是否有crash、anr(在根目錄下的/mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt)


其實僅僅就是拿到手機後,將/mnt/sdcard放入whitelist.txt或則blacklist.txt,裏面放上應用包名,然後adb shell---》mokey命名,就可以了


命令解釋:

參數: --throttle <毫秒>

用於指定用戶操作(即事件)間的時延,單位是毫秒;

參數: --ignore-crashes

用於指定當應用程序崩潰時(Force & Close錯誤),Monkey是否停止運行。如果使用此參數,即使應用程序崩潰,Monkey依然會發送事件,直

到事件計數完成。
參數: --ignore-timeouts

用於指定當應用程序發生ANR(Application No Responding)錯誤時,Monkey是否停止運行。如果使用此參數,即使應用程序發生ANR錯誤,Monkey依然會發送事件,直到事件計數完成。
參數: --ignore-security-exceptions

用於指定當應用程序發生許可錯誤時(如證書許可,網絡許可等),Monkey是否停止運行。如果使用此參數,即使應用程序發生許可錯誤,Monkey依然會發送事件,直到事件計數完成。

參數: ignore-native-crashes
忽略本地代碼導致的崩潰。設置忽略後,Monkey將執行完所有的事件,不會因此停止

參數: --monitor-native-crashes

用於指定是否監視並報告應用程序發生崩潰的本地代碼。

參數: -s
用於指定偽隨機數生成器的seed值,如果seed相同,則兩次Monkey測試所產生的事件序列也相同的。示例:
Monkey測試1:adb shell monkey -p com.htc.Weather –s10 100

Monkey 測試2:adb shell monkey -p com.htc.Weather–s 10 100
兩次測試的效果是相同的,因為模擬的用戶操作序列(每次操作按照一定的先後順序所組成的一系列操作,即一個序列)是一樣的。操作序列雖然是隨機生成的,但是只要我們指定了相同的Seed值,就可以保證兩次測試產生的隨機操作序列是完全相同的,所以這個操作序列偽隨機的;


參數: -v

用於指定反饋信息級別(信息級別就是日誌的詳細程度),總共分3個級別,分別對應的參數如下表所示:

日誌級別 Level 0

示例 adb shell monkey -p com.htc.Weather –v 100

說明 缺省值,僅提供啟動提示、測試完成和最終結果等少量信息

日誌級別 Level 1

示例 adb shell monkey -p com.htc.Weather –v -v 100

說明 提供較為詳細的日誌,包括每個發送到Activity的事件信息

日誌級別 Level 2

示例 adb shell monkey -p com.htc.Weather –v -v –v 100

說明 最詳細的日誌,包括了測試中選中/未選中的Activity信息

Monkey測試手機BUG重現及解決方法