Monkey测试

2018-04-17  本文已影响75人  __HAPPINESS_yh

Monkey启动的命令行脚本为:monkey [options] < count >

Options可以分为5类 1. 基本配置类参数 2. 事件类型和频率参数 3. 约束限制类参数 4. 调试类参数 5.官方隐藏类参数

Monkey启动

shell启动

adb shell
monkey [options] <count>

monkey 启动后会不断的向被测对象发送随机事件流,直到事件执行完毕或者发生异常时才停止,停止monkey 的方法是杀死monkey的进程

adb shell ps | grep monkey
adb shell kill pid

Monkey测试方法

  1. 常规稳定性测试
    adb shell monkey -p com.xxx.xxx --pct-touch 40 --pct-motion 25 --pct-appswitch 10 --pct-rotation 5 -s 12358 --throttle 400 --ignore-crashes --ignore-timeouts -v 500000

    • -p 获取测试应用的包名
      > adb shell
      pm list package
    • --pct-xxx 限制monkey执行的事件类型和占比
    • -s 指定命令执行的seed值
      根据seed值生成对应的事件流,同一个seed生成的事件流是完全相同的,指定seed值是为了发现问题时便于复现
    • --throttle参数控制monkey每个操作之间的时间间隔
    • --ignore-crash --ignore-timeouts 是操作遇到意外时继续执行
    • -v指定log的详细级别
  2. 自定义脚本的稳定性测试
    让monkey测试某个特定场景(执行固定的事件流),用户将monkey脚本的规范编写好脚本,存放到手机上,启动monkey 通过 -f scriptfile参数调用脚本即可。

    Monkey 脚本只能通过坐标的方式来定位点击和移动事件的屏幕位置,这里就需要提前获取坐标信息,最简单的方法就是打开手机中开发人员选项,打开“显示指针位置”,随后,在屏幕上的每次操作在导航栏上都会显示坐标信息

    编写好脚本后,存放到手机或模拟器的sdcard中
    adb push monkey.script /sdcard/
    执行脚本
    adb shell monkey -f /sdcard/monkey.script -v 1

  3. 结合辅助命令,获取更多信息

    • 获取 logcat 日志信息
      adb shell logcat -v time>log.txt

    • 获取内存信息
      adb shell dumpsys meminfo <进程名>

    • 获取CPU消耗信息
      adb shell top -n 1|find "进程名"

    • 获取电量信息
      adb shell dumpsys battery

    • 获取GPU信息
      adb shell dumpsys gfxinfo <进程名>

    • 获取流量信息
      adb shell cat/proc/uid_stat/<被测应用的UID>/tcp_rcv
      查看被测应用的进程ID(PID)
      adb shell ps | grep <被测应用包名>
      查看被测应用的用户ID(UID)
      adb shell cat /proc/$pid/status

      日志保存

      • 保存在PC中
        adb shell monkey [option] <count> >d:\monkey.txt
      • 保存在手机中
        adb shell
        monkey [option] <count> > /mnt/sdcard/monkey.txt
      • 标注流与错误流分开保存
        monkey [option] <count> 1 >/sdcard/monkey.txt 2>/sdcard/error.txt
上一篇 下一篇

猜你喜欢

热点阅读