一、monkey測試簡介
二、monkey程式介紹
1) monkey程式由android系統自帶,使用java語言寫成,在android檔案系統中的存放路徑是:/system/framework/monkey.jar;
三、monkey指令的簡單幫助
要擷取monkey指令自帶的簡單幫助,在cmd中執行指令:
adb shell monkey –help
四、monkey指令參數介紹
1) 參數: -p
參數-p用于限制限制,用此參數指定一個或多個包(package,即app)。指定
包之後,monkey将隻允許系統啟動指定的app。如果不指定包,monkey将允許系統啟動裝置中的所有app。
* 指定一個包: adb shell monkey -p com.htc.weather 100
說明:com.htc.weather為包名,100是事件計數(即讓monkey程式模拟100次随機使用者事件)。
* 指定多個包:adb shell monkey -p com.htc.weather –p com.htc.pdfreader -p com.htc.photo.widgets 100
* 不指定包:adb shell monkey 100
說明:monkey随機啟動app并發送100個随機事件。
* 要檢視裝置中所有的包,在cmd視窗中執行以下指令:
>adb shell
#cd data/data
#ls
2) 參數: -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資訊
3)參數: -s
用于指定僞随機數生成器的seed值,如果seed相同,則兩次monkey測試所産生的事件序列也相同的。
* 示例:
monkey測試1:adb shell monkey -p com.htc.weather –s 10 100
monkey 測試2:adb shell monkey -p com.htc.weather –s 10 100
兩次測試的效果是相同的,因為模拟的使用者操作序列(每次操作按照一定的先後順序所組成的一系列操作,即一個序列)是一樣的。操作序列雖 然是随機生成的,但是隻要我們指定了相同的seed值,就可以保證兩次測試産生的随機操作序列是完全相同的,是以這個操作序列僞随機的;
4) 參數: --throttle <毫秒>
用于指定使用者操作(即事件)間的時延,機關是毫秒;
* 示例:adb shell monkey -p com.htc.weather –throttle 3000 100
5) 參數: --ignore-crashes
用于指定當應用程式崩潰時(force & close錯誤),monkey是否停止運作。如果使用此參數,即使應用程式崩潰,monkey依然會發送事件,直到事件計數完成。
* 示例1:adb shell monkey -p com.htc.weather --ignore-crashes 1000
測試過程中即使weather程式崩潰,monkey依然會繼續發送事件直到事件數目達到1000為止;
* 示例2:adb shell monkey -p com.htc.weather 1000
測試過程中,如果weather程式崩潰,monkey将會停止運作。
6) 參數: --ignore-timeouts
用于指定當應用程式發生anr(application no responding)錯誤時,monkey是否停止運作。如果使用此參數,即使應用程式發生anr錯誤,monkey依然會發送事件,直到事件計數完成。
7) 參數: --ignore-security-exceptions
用于指定當應用程式發生許可錯誤時(如證書許可,網絡許可等),monkey是否停止運作。如果使用此參數,即使應用程式發生許可錯誤,monkey依然會發送事件,直到事件計數完成。
8) 參數: --kill-process-after-error
用于指定當應用程式發生錯誤時,是否停止其運作。如果指定此參數,當應用程式發生錯誤時,應用程式停止運作并保持在目前狀态(注意:應用程式僅是靜止在發生錯誤時的狀态,系統并不會結束該應用程式的程序)。
9) 參數: --monitor-native-crashes
用于指定是否監視并報告應用程式發生崩潰的本地代碼。
10) 參數: --pct-{+事件類别} {+事件類别百分比}
用于指定每種類别事件的數目百分比(在monkey事件序列中,該類事件數目占總事件數目的百分比)
參數:
使用說明:
示例:
--pct-touch {+百分比}
調整觸摸事件的百分比(觸摸事件是一個down-up事件,它發生在螢幕上的某單一位置)
adb shell monkey -p com.htc.weather --pct-touch 10 1000
--pct-motion {+百分比}
調整動作事件的百分比(動作事件由螢幕上某處的一個down事件、一系列的僞随機事件和一個up事件組成)adb shell monkey -p com.htc.weather --pct-motion 20 1000
--pct-trackball {+百分比}
adb shell monkey -p com.htc.weather --pct-trackball 30 1000
--pct-nav {+百分比}
調整“基本”導航事件的百分比(導航事件由來自方向輸入裝置的up/down/left/right組成)
adb shell monkey -p com.htc.weather --pct-nav 40 1000
--pct-majornav {+百分比}
調整“主要”導航事件的百分比(這些導航事件通常引發圖形界面中的動作,如:5-way鍵盤的中間按鍵、回退按鍵、菜單按鍵)
adb shell monkey -p com.htc.weather --pct-majornav 50 1000
--pct-syskeys {+百分比}
調整“系統”按鍵事件的百分比(這些按鍵通常被保留,由系統使用,如home、back、start call、end call及音量控制鍵)
adb shell monkey -p com.htc.weather --pct-syskeys 60 1000
--pct-appswitch {+百分比}
調整啟動activity的百分比。在随機間隔裡,monkey将執行一個startactivity()調用,作為最大程度覆寫包中全部activity的一種方法
adb shell monkey -p com.htc.weather --pct-appswitch 70 1000
--pct-anyevent {+百分比}
調整其它類型事件的百分比。它包羅了所有其它類型的事件,如:按鍵、其它不常用的裝置按鈕、等等
adb shell monkey -p com.htc.weather
--pct -anyevent 100 1000* 指定多個類型事件的百分比:
adb shell monkey -p com.htc.weather --pct-anyevent 50 --pct-appswitch 50 1000
注意:各事件類型的百分比總數不能超過100%;