Monkey Test
本文轉(zhuǎn)自:https://www.cnblogs.com/ckie/p/6883843.html
?
1.1 Monkey測試簡介
Monkey測試是Android平臺自動化測試的一種手段,通過Monkey程序模擬用戶觸摸屏幕、滑動Trackball、按鍵等操作來對設(shè)備上的程序進行壓力測試,檢測程序多久的時間會發(fā)生異常。
1.2 Monkey程序介紹
1) Monkey程序由Android系統(tǒng)自帶,使用Java語言寫成,在Android文件系統(tǒng)中的存放路徑是:/system/framework/monkey.jar;
2) Monkey.jar程序是由一個名為“monkey”的Shell腳本來啟動執(zhí)行,shell腳本在Android文件系統(tǒng)中的存放路徑 是:/system/bin/monkey;這樣就可以通過在CMD窗口中執(zhí)行: adb shell monkey {+命令參數(shù)}來進行Monkey測試了。
1.3 Monkey命令的簡單幫助
要獲取Monkey命令自帶的簡單幫助,在CMD中執(zhí)行命令:?
adb shell monkey –help
1.4 Monkey命令參數(shù)介紹
可參考MTK相關(guān)文檔。
Android_Monkey_Test_SOP.pdf
Monkey_Test_SOP_Customer_MT6572_4.x .pdf
1.5 Monkey測試步驟
步驟1:下載 user 版本后手動導(dǎo)入 APR 工具。
步驟2:導(dǎo)入完畢后重啟手機,連接 usb 線,運行 logServerInstall.bat。
步驟3:運行后手機會自動重啟,重啟完畢后手機端鍵入 *#*#2012#*#* ,能夠進入對應(yīng)界面即為 apr 安裝成功。
步驟4:手機連接電腦,開啟 adb 鍵入 adb shell ps logserver,查詢 logserver的PID 值,然后鍵入 adb shell kill PID(logserver PID)。
步驟5:再次鍵入 adb shell ps logserver 查看 logserser 已被 kill 掉。
步驟6:手機連接電腦,開啟 USB 存儲,在手機內(nèi)存(或 SD 卡)中,新建一個名為 whitelist.txt 文件,該文件中輸入想跑的模塊名,每個模塊輸入后回車輸入下一個,若對模塊名稱不熟悉可參考 monkey 測試報告,內(nèi)有模塊排練信息。
例如:com.chinamobile.cmccwifi
com.cmcc.mobilevideo
com.hisunflytone.android
步驟7:上一步完成后,手機端進入對應(yīng)的apk模塊,如:whitelist中想跑新浪微薄,uc瀏覽器的話,手機端分別進入這些應(yīng)用,把首次使用提示框點掉,記得勾選上永遠不提示的選項以免跑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結(jié)束后手機連接電腦,運行g(shù)etDataLog.bat,生成 datalog。連接usb存儲,在是手機上找到Stability_base.txt文件,查看最后修改時間,該時間即為monkey運行最后結(jié)束時間。
1.6 Monkey測試問題分析及處理技巧
Monkey測試主要是測試負責,研發(fā)這邊配合測試進行問題復(fù)現(xiàn)及給出測試建議,重點工作還是monkey問題分析,包括凍屏、死機重啟、crash等。由于這類問題分析起來比較麻煩,所以一般如果沒有相關(guān)分析經(jīng)驗可以先定位問題,準備好相關(guān)的log配合MTK分析或者找部門內(nèi)部有相關(guān)經(jīng)驗的研發(fā)人員配合分析。
1.7 Monkey測試注意事項
1. 測試關(guān)閉所有網(wǎng)絡(luò)開關(guān)(wifi及數(shù)據(jù)連接)
2. 開啟安全設(shè)置下的未知來源
3. 手機連接電源充電
4. 若有有關(guān)于音頻的模塊,請插入耳機避免影響其他同事
5. 若測試信息模塊時需要安裝測試工具testwizard.apk,自動生成通話記錄,短信(數(shù)量為10)
6. 若測試文件管理器需要在T卡內(nèi)存放有圖片/音樂/apk/視頻/txt這類文件
7. 測試圖庫是需要T卡內(nèi)存放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等。
測試前首先關(guān)閉MTK log,將sdcard卡和手機內(nèi)存中的舊的log清理趕緊,最相關(guān)干擾文件一并清理干凈,否則后期取出log很容易造成困擾。
?
注意事項:
1)每個模塊使用3臺手機測試,測試完成后恢復(fù)出廠設(shè)置在測試其他模塊,避免殘留文件影響其他模塊測試結(jié)果.
2)測試部分需要資源的模塊,測試前需要先導(dǎo)入資源.
信息:導(dǎo)入500條短信
聯(lián)系人:導(dǎo)入500個聯(lián)系人
音樂:導(dǎo)入100個歌曲
視頻:導(dǎo)入20個視頻
瀏覽器:插入有錢的SIM卡,開啟數(shù)據(jù)連接,連接WIfi
FM收音機:插入耳機
Email:登錄郵箱帳號
3)部分模塊第一次進入有使用說明或者協(xié)議說明,需要手動點擊完成后在測試.
應(yīng)用市場:勾選不再提醒,完成所有提示確認
主題:勾選不再提醒,完成所有提示確認
相機:勾選不再提醒,完成所有提示確認
圖庫:勾選不再提醒,完成所有提示確認
......
因為應(yīng)用太多就不列舉出來了,每個模塊測試前先手動進入查看,完成所有導(dǎo)航在進行測試.
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應(yīng)用的包名即可,表示只跑指定apk,如果是在手機根目錄中放blacklist.txt,填寫相應(yīng)包名,指跑除blacklist.txt上指定應(yīng)用的所有應(yīng)用。Monkey跑完后檢查log里面是否有crash、anr(在根目錄下的/mnt/sdcard/Stability_base.txt 2>> /mnt/sdcard/Stability_base_err.txt)
其實僅僅就是拿到手機后,將/mnt/sdcard放入whitelist.txt或則blacklist.txt,里面放上應(yīng)用包名,然后adb shell---》mokey命名,就可以了
?
命令解釋:
參數(shù): --throttle <毫秒>
用于指定用戶操作(即事件)間的時延,單位是毫秒;
參數(shù): --ignore-crashes
用于指定當應(yīng)用程序崩潰時(Force & Close錯誤),Monkey是否停止運行。如果使用此參數(shù),即使應(yīng)用程序崩潰,Monkey依然會發(fā)送事件,直到事件計數(shù)完成。
參數(shù): --ignore-timeouts
用于指定當應(yīng)用程序發(fā)生ANR(Application No Responding)錯誤時,Monkey是否停止運行。如果使用此參數(shù),即使應(yīng)用程序發(fā)生ANR錯誤,Monkey依然會發(fā)送事件,直到事件計數(shù)完成。
參數(shù): --ignore-security-exceptions
用于指定當應(yīng)用程序發(fā)生許可錯誤時(如證書許可,網(wǎng)絡(luò)許可等),Monkey是否停止運行。如果使用此參數(shù),即使應(yīng)用程序發(fā)生許可錯誤,Monkey依然會發(fā)送事件,直到事件計數(shù)完成。
參數(shù): ignore-native-crashes
忽略本地代碼導(dǎo)致的崩潰。設(shè)置忽略后,Monkey將執(zhí)行完所有的事件,不會因此停止
參數(shù): --monitor-native-crashes
用于指定是否監(jiān)視并報告應(yīng)用程序發(fā)生崩潰的本地代碼。
參數(shù): -s
用于指定偽隨機數(shù)生成器的seed值,如果seed相同,則兩次Monkey測試所產(chǎn)生的事件序列也相同的。示例:
Monkey測試1:adb shell monkey -p com.htc.Weather –s10 100
Monkey 測試2:adb shell monkey -p com.htc.Weather–s 10 100
兩次測試的效果是相同的,因為模擬的用戶操作序列(每次操作按照一定的先后順序所組成的一系列操作,即一個序列)是一樣的。操作序列雖然是隨機生成的,但是只要我們指定了相同的Seed值,就可以保證兩次測試產(chǎn)生的隨機操作序列是完全相同的,所以這個操作序列偽隨機的;
參數(shù): -v
用于指定反饋信息級別(信息級別就是日志的詳細程度),總共分3個級別,分別對應(yīng)的參數(shù)如下表所示:
日志級別 Level 0
示例 adb shell monkey -p com.htc.Weather –v 100
說明 缺省值,僅提供啟動提示、測試完成和最終結(jié)果等少量信息
?
日志級別 Level 1
示例 adb shell monkey -p com.htc.Weather –v -v 100
說明 提供較為詳細的日志,包括每個發(fā)送到Activity的事件信息
?
日志級別 Level 2
示例 adb shell monkey -p com.htc.Weather –v -v –v 100
說明 最詳細的日志,包括了測試中選中/未選中的Activity信息。
總結(jié)
以上是生活随笔為你收集整理的Monkey Test的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Error(6,35)java: 程序包
- 下一篇: Maven--命令