Monkey 測試使用大量隨機操作對 App 進行壓力測試。
本文基于 openSuse + Lenovo A5500 為例,介紹如何進行 Monkey 測試。
準備
- 首先你要有一部 Android 手機;
- 然后你要有一臺電腦,強烈推薦使用 GNU/Linux ;
- 安裝待測 App F-Droid ,它是一款開源軟件,用來下載和更新開源軟件。
- 啟用手機的開發(fā)者模式并連接至電腦。
- 獲取待測 App 的包名
-
adb shell pm list packages命令可獲取所有已安裝的 App 的包名。 - F-Droid 的包名為
org.fdroid.fdroid
-
執(zhí)行
adb shell #在本機執(zhí)行
monkey -p org.fdroid.fdroid -v 50 #在手機 shell 中執(zhí)行,對F-Droid做50次操作
要想取得好的效果,需要對 monkey 命令的參數(shù)進行細致的調整,給出一例:
monkey -p org.fdroid.fdroid --monitor-native-crashes --pct-touch 80 --pct-motion 15 --pct-nav 5 -s 900 -v --throttle 200 5000
執(zhí)行后發(fā)現(xiàn)的一處ANR:
// NOT RESPONDING: org.fdroid.fdroid (pid 17726)
ANR in org.fdroid.fdroid (org.fdroid.fdroid/.AppDetails), time=18200186
Reason: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 7. Wait queue head age: 8622.1ms.)
更多使用方式可以使用monkey –help 了解。
補:中斷測試
從本機發(fā)起的 Monkey 測試,即使命令中斷,手機端還是會執(zhí)行。
adb shell連入手機后ps |grep monkey查看進程號殺死即可。
問題
- 測試時會下滑拉出狀態(tài)欄,導致關閉網(wǎng)絡。
- 測試時出現(xiàn)手機假變磚,進入
adb shell后執(zhí)行reboot后恢復,測試有風險,入行需謹慎,請僅在使用公司手機時大膽嘗試????。