monkey測試.常用的adb命令和monkey命令
Monkey 就是SDK中附帶的一個工具。Monkey是Android中的一個命令列工具,可以執行在模擬器裡或實際裝置中。它向系統傳送偽隨機的使用者事件流(如按鍵輸入、觸控式螢幕輸入、手勢輸入等),實現對正在開發的應用程式進行壓力測試。Monkey測試是一種為了測試軟體的穩定性、健壯性的快速有效的方法。
** 檢視裝置連線
adb devices
** 列出手機已安裝的包名
adb shell pm list packages 手機裝的app所有包名
adb shell pm list packages -s 系統所有包名
adb shell pm list packages -3 列出除了系統應用的第三方應用包名
** 查詢包
adb shell pm list package |findstr baidu
或adb shell下,pm list package |grep baidu
** 清除應用資料
pm clear com.baidu.input
** 安裝解除安裝
adb install d:\com.baidu.input
adb uninstall com.baidu.input
** 檢視monkey程序
windows: adb shell ps |findstr monkey
linux: $adb shell
$ps | grep monkey
** 殺掉程序
adb shell kill [pid程序號]
** -p 指定包.可指定一個包或幾個包
adb shell monkey -p com.baidu.input -p com.sohu.input 1000
** 日誌 -v
-v -v -v 增加-v增加日誌的詳情級別
adb shell monkey -p com.baidu.input -v -v -v 1000
** -s (seed)偽隨機數生成器的種子值,相同的種子值執行monkey,事件的序列相同
adb shell monkey -p com.baidu.input -s 1234 重現種子值為1234的事件序列
** -throttle 事件間隔.事件間隔300ms,
adb shell monkey -p com.baidu.input --throttle 300 -v -v 1000
** -pct 動作事件 Monkey的事件種類一般是11種,不同的Android SDK中的Event percentages種類和順序也不同哦。
--pct-touch 70 觸控事件百分比70
--pct-motion 5 手勢事件百分比70
--pct-trackball 5 軌跡球事件百分比10
--pct-pinchzoom 2 縮放事件百分比2
--pct-rotation 0 螢幕旋轉事件百分比0
--pct-nav 0 基本導航事件百分比0
--pct-majornav 5 主要導航事件百分比5
--pct-syskeys 5 系統事件百分比 5
--pct-appswitch 2 Activity啟動事件百分比2
--pct-flip 2 鍵盤翻轉事件百分比
--pct-anyevent 2 其他事件百分比
** -ignore 忽略錯誤事件
--ignore-crashes 忽略crash
--ignore-timeouts 忽略timeouts
--ignore-security-exceptions 忽略許可權錯誤
--ignore-native-crashes 忽略本地應用程式發生崩潰
** -kill-process-after-error 錯誤後停止應用
** -monitor-native-crashes Android系統原生程式碼中的監視和報告崩潰
** 2>&1 錯誤重定向 每個程序都和三個系統檔案相關聯.標準輸入stdin,標準輸出stdout,標準錯誤stderr.檔案描述符分別為0,1,2
所以這裡的2>&1,代表把標準錯誤也輸出到標準輸出中.這樣標準輸出的日誌內容就包含了標準錯誤的日誌內容
1 ./test.sh > 111.log 標準錯誤輸出到前臺,標準輸出輸出到111.log.log日誌不包含報錯內容
2 ./test.sh > 222.log 2>&1 標準錯誤和標準輸出都輸出到222.log日誌中
3 ./test.sh > info.log 2>err.log 標準輸出輸出到info.log 標準錯誤重定向到err.log
** 儲存日誌
adb shell monkey -p com.baidu.input -v -v -v 1000 >d:\monkey.txt 2>&1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 壓測命令
****cmd下****
日誌儲存到pc,跑monkey過程中需一直連線資料線到電腦:
adb shell monkey -p com.baidu.input --ignore-crashes --ignore-timeouts -ignore-security-exceptions --pct-touch 70 --pct-motion 25 --pct-majornav 5 -v -v -v --throttle 300 100000 > d:\monkey1.txt
monkey -p 包名 忽略crash,忽略timeout,忽略許可權異常,觸控事件70,手勢事件25,主要導航事件5,日誌三級,間隔300ms,100000次事件,輸出到d盤monkey.txt.標準錯誤也輸出到標準輸出中.
** 匯出手機日誌
adb logcat -v threadtime >d:/loacat1.txt
** cpu 記憶體監控命令
adb shell top -d 1 |findstr com.baidu.input > d:/cpu1.txt
** 停止程序命令
adb shell am force-stop com.baidu.xxx
****adb shell下
日誌儲存到手機,斷開資料線也可正常進行,最後把日誌從手機匯出到pc進行檢視.
abd shell
$cd /sdcard
$mkdir monkeytest
$cd monkeytest
monkey命令:
monkey -p com.baidu.input --ignore-crashes --ignore-timeouts -ignore-security-exceptions --pct-touch 70 --pct-motion 25 --pct-majornav 5 -v -v -v --throttle 300 100000 > monkey1.txt
匯出日誌
adb pull /sdcard/monkeytest/monkey1.txt d:/
**日誌處理: