1、直接使用adb命令
adb shell monkey -p 包名 <event-count>

例:
1)adb shell monkey -p 包名-s 500 --throttle 100 --ignore-crashes --ignore-timeouts --monitor-native-crashes -
v -v 10000
產(chǎn)生時(shí)間序列的種子值:500,事件間延遲 100 忽略程序崩潰 、 忽略超時(shí) 、 監(jiān)視本地程序崩潰 、 詳細(xì)信息級(jí)別為2 , 產(chǎn)生 10000個(gè)事件
2)adb shell monkey -p com.vlife.stage --throttle 100 --ignore-crashes --ignore-timeouts --kill-process-after-error
--pct-touch 35
--pct-syskeys 30
--pct-appswitch 35 --hprof -v -v -v 50000
注意:這個(gè)命令定義了事件的百分比,但并沒有定義種子值,在實(shí)際應(yīng)用中是非常不推薦的,只有同樣的種子值才會(huì)產(chǎn)
生同樣的序列,若遇見隨機(jī)問題,沒有種子數(shù)則無法復(fù)現(xiàn)該問題,為了方便重現(xiàn)問題一定要加-s, 另外日志的級(jí)別建議選擇詳細(xì)級(jí)別,三個(gè)-v -v -v
2、使用白名單的方法
1)使用adb命令將framework.jar 和monkey.jar 文件放到sdcard下(文件路徑:https://github.com/zhangzhao4444/Maxim)
adb push framework.jar monkey.jar 文件到 /sdcard
2)執(zhí)行命令運(yùn)行monkey(可根據(jù)需求改變參數(shù))
adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p 包名 --uiautomatormix --running-minutes 60
參數(shù)說明:
1.tv.panda.test.monkey.Monkey 主調(diào)入口 無需修改
2.策略模式
--uiautomatormix 混合模式(70%控件解析隨機(jī)點(diǎn)擊,其余30%按原Monkey事件概率分布)
--pct-uiautomatormix n 可自定義混合模式中控件解析事件概率
--uiautomatordfs DFS深度遍歷算法(優(yōu)化版)(注 Android5不支持dfs)
3.--running-minutes 60 執(zhí)行60分鐘monkey
4.--act-whitelist-file /sdcard/awl.strings 在sdcard中自定義Activity白名單(鎖定跳轉(zhuǎn)只可進(jìn)入其中指定的Activity)
例如:

5.其他參數(shù)及用法同原始Monkey