Monkey 是android自带的黑盒测试工具,一般通过随机触发界面事件,来确定应用是否会发生异常,多用于android应用的稳定性、压力测试
基本命令:
adb shell monkey [options] <event-count>
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
[-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
[--ignore-crashes] [--ignore-timeouts]
[--ignore-security-exceptions]
[--monitor-native-crashes] [--ignore-native-crashes]
[--kill-process-after-error] [--hprof]
[--pct-touch PERCENT] [--pct-motion PERCENT]
[--pct-trackball PERCENT] [--pct-syskeys PERCENT]
[--pct-nav PERCENT] [--pct-majornav PERCENT]
[--pct-appswitch PERCENT] [--pct-flip PERCENT]
[--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]
[--pct-permission PERCENT]
[--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
[--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
[--wait-dbg] [--dbg-no-events]
[--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
[--port port]
[-s SEED] [-v [-v] ...]
[--throttle MILLISEC] [--randomize-throttle]
[--profile-wait MILLISEC]
[--device-sleep-time MILLISEC]
[--randomize-script]
[--script-log]
[--bugreport]
[--periodic-bugreport]
[--permission-target-system]
COUNT
示例:
1、随机模拟1000次操作测试应用
adb shell monkey -p com.conti.greatwallcarrental -v 1000
2、执行monkey脚本,需将脚本需放在android终端执行
adb shell monkey -f <script> count
monkey.script 脚本内容如下(针对计算机应用):
# Start of Script
type= user
count= 1
speed= 1.0
start data >>
LaunchActivity(com.android.calculator2, com.android.calculator2.Calculator)
DispatchPress(KEYCODE_3)
UserWait(200)
DispatchPress(KEYCODE_2)
UserWait(200)
DispatchPress(KEYCODE_PLUS)
UserWait(200)
DispatchPress(KEYCODE_9)
UserWait(200)
DispatchPress(KEYCODE_2)
UserWait(200)
DispatchPress(KEYCODE_EQUALS)
UserWait(200)