Android monkey測試小記

前言:公司盒子將要進行monkey測試, 寫此博文做技術儲備。
原文出處:http://blog.csdn.net/u014158743/article/details/52540705

monkey測試

啓動你的軟件並且觸發500個事件

$ adb shell monkey -v -p your.package.name 500

全部命令選項:

–help 幫助
-v {0,1,2}三級,-v越多,反饋信息更詳細
-s 僞隨機數生成器
–throttle 延遲執行速度,缺省則儘快
–pct-touch <%> down-up事件百分比
–pct-motion <%> down-[僞隨機事件]-up
–pct-trackball <%> 軌跡事件百分比, 軌跡事件爲move,有時伴有點擊
–pct-nav <%> 基本導航事件百分比,上下左右
–pct-majornav <%> 主要導航事件的百分比,5-way的中間按鍵,回退,菜單等
–pct-syskeys <%> 系統按鍵事件的百分比
–pct-appswitch <%> 啓動activity的百分比
–pct-anyevent <%> 其它事件的百分比
-p 指定啓動包下面的activity
-c 只允許系統指定某個類別列出的activity, 一個c只能用於一個類別
–dbg-no-events 設置此選項, monkey將執行初始啓動, 進入到一個測試activity, 然後不再進一步生成事件
–hprof 將在monkey事件序列之前和之後立即生成profiling報告
–ignore-crashes 無視程序崩潰或失控異常
–ignore-timeouts 無視anr異常
–ignore-security-exceptions 無視許可異常
–kill-process-after-error 出錯殺死進程
–monitor-native-crashes 監視並報告Android系統中本地代碼的崩潰事件
–wait-dbg 停止執行中的monkey, 直到有調試器和它相連接

執行單一apk:

monkey –p -c -s <限制語句> –throttle -v 執行次數> C:\monkey_test.txt

執行apk集合:

monkey –pkg-blacklist-file /data/blacklist.txt -c -s <限制語句> –throttle -v 執行次數> C:\blacklist_test.txt //執行黑名單以外的應用

monkey –pkg-whitelist-file /data/whitelist.txt -c -s <限制語句> –throttle -v 執行次數 > C:\whitelist_test.txt //執行白名單的應用

停止monkey

1. monkey運行時:adb shell ps|grep monkey返回的第一個數字就是monkey的進程號
2. adb shell kill [進程號]

實例小記:

動作log在命令行:

adb shell monkey -v -p com.xinwo.health –pct-appswitch 0 –throttle 500 100000

動作log在電腦:

adb shell monkey -v -p com.xinwo.health –pct-appswitch 0 –throttle 500 100000 > ./monkeytest

動作log在盒子:

adb shell
monkey -v -p com.xinwo.health –pct-appswitch 0 –throttle 500 100000 > /data/monkeytest

根據實際測試需要添加參數

1. --ignore-timeouts
2. --ignore-crashes
3. --ignore-security-exceptions 等.

查看日誌log:

1. as的logcat
2. log在命令行: adb logcat -s tag
3. log在電腦: adb logcat > ./log
4. log在盒子: adb shell 然後 logcat > /data/log

動作log解析

// 僞隨機碼和monkey執行次數
:Monkey: seed=1474943047616 count=100
// 被測試應用的包名
:AllowPackage: com.xinwo.health
// 沒指定-c默認去找有LAUNCHER或有MONKEY的activity
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:// 執行各動作的百分比
//   0: 15.306122%
//   1: 10.204082%
//   2: 2.0408163%
//   3: 15.306122%
//   4: -0.0%
//   5: 25.510204%
//   6: 15.306122%
//   7: 2.0408163%
//   8: -0.0%
//   9: 1.0204082%
//   10: 13.265306%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.xinwo.health/.activity.MainActivity;end
// 找到了MainActivity並啓動
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xinwo.health/.activity.MainActivity } in package com.xinwo.health
// 點擊事件
:Sending Touch (ACTION_DOWN): 0:(616.0,101.0)
:Sending Touch (ACTION_UP): 0:(615.6293,106.84831)
// 滑動事件
:Sending Trackball (ACTION_MOVE): 0:(0.0,1.0)
:Sending Touch (ACTION_DOWN): 0:(814.0,380.0)
:Sending Touch (ACTION_UP): 0:(818.69,399.07745)
:Sending Touch (ACTION_DOWN): 0:(301.0,397.0)
:Sending Touch (ACTION_UP): 0:(320.92767,396.68716)
:Sending Touch (ACTION_DOWN): 0:(207.0,405.0)
:Sending Touch (ACTION_UP): 0:(161.20079,390.50723)
:Sending Touch (ACTION_DOWN): 0:(665.0,379.0)
:Sending Touch (ACTION_UP): 0:(674.58777,359.97778)
    // Allowing start of Intent { cmp=com.xinwo.health/.activity.TestChooseActivity } in package com.xinwo.health
:Sending Trackball (ACTION_MOVE): 0:(0.0,-5.0)
:Sending Touch (ACTION_DOWN): 0:(282.0,366.0)
:Sending Touch (ACTION_UP): 0:(290.99738,377.07254)
    // Allowing start of Intent { cmp=com.xinwo.health/.activity.TestProcessActivity } in package com.xinwo.health
:Sending Touch (ACTION_DOWN): 0:(816.0,416.0)
:Sending Touch (ACTION_UP): 0:(808.4478,401.9289)
:Sending Touch (ACTION_DOWN): 0:(206.0,339.0)
:Sending Touch (ACTION_UP): 0:(287.30112,302.14993)
:Sending Touch (ACTION_DOWN): 0:(303.0,236.0)
// 成功執行了100次
Events injected: 100
:Sending rotation degree=0, persist=false
// 執行時間和在期間內聯網等情況.
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=15814ms (0ms mobile, 0ms wifi, 15814ms not connected)
// Monkey finished
發佈了41 篇原創文章 · 獲贊 10 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章