下载安卓APP箭头
箭头给我发消息

客服QQ:3315713922
论坛 >移动开发 >移动APP测试之Monkey Test 运用

移动APP测试之Monkey Test 运用

TestBird发布于 2017-02-09 14:27查看:726


 

MonkeyAndroid平台自动化测试的一种手段,可以在模拟器里或实际设备中运行,它向系统发送伪随机的用户事件流,如按键输入、触摸屏输入、手势输入等,实现对正在开发的应用程序进行压力测试。

 

当然对于移动APP测试monkey测试出了压力测试外,也可以做做简单的机型配适,就是测试App是否会出现crash等异常,以此来判读其释放与机型适配,可以发现程序无响应问题和崩溃问题。

 

接下来简单说说:

 

Monkey程序由Android系统自带,使用Java语言写成,在Android文件系统中的存放路径是:/system/framework/monkey.jar

 

Monkey.jar程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在Android文件系统中的存放路径是:/system/bin/monkey

 

特征

1 测试的对象仅为应用程序包,有一定的局限性。

2 Monky测试使用的事件流数据流是随机的,不能进行自定义。

3 可对MonkeyTest的对象,事件数量,类型,频率等进行设置。

 

这样就可以通过在CMD窗口中执行: adb shell monkey +命令参数}来进行Monkey测试了。

 

基本使用

 

1. 进入monkey

 

命令:adb shell/system/bin/monkey

 

2. 运行monkey

 

命令:adb shell monkey <event-count> <event-count>是指随机发送事件数

adb shell monkey 100,运行monkey并执行了100件随机事件。

 

3. monkey常规类命令

 

adb shell monkey -h 显示monkey参数帮助信息usage

adb shell monkey -v 打印出日志信息,每个-v将增加反馈信息的级别,最多支持3-v

 

4. monkey事件类命令

 

adb shell monkey -f <scriptfile> <event-count> monkey运行指定monkey脚本,<scriptfile> 为测试脚本名,<event-count>是指循环次数。

adb shell monkey -s <seed> <event-count> 可以重复之前的随机操作,-s 后接随机数的生成器的seed值。

adb shell monkey --throttle <milliseconds> 表示每个事件之间的固定延迟事件,时间的单位为ms,若后面不接时间,monkey将不会延迟

事件百分比

adb shell monkey --ptc-touch <percent> 设定触摸事件的百分比

adb shell monkey --ptc-motion <percent> 设定动作事件的百分比

adb shell monkey --ptc-trackball <percent> 设定轨迹球事件的百分比

adb shell monkey --ptc-nav <percent> 设定基本导航事件的百分比

adb shell monkey --ptc-majornav <percent> 设定主要导航事件的百分比

adb shell monkey --ptc-syskeys <percent> 设定按键事件的百分比

adb shell monkey --ptc-appswitch <percent> 设定启动事件的百分比

adb shell monkey --ptc-anyevent <percent> 其他类型事件的百分比,包括keypress、不常用button以及其他未提及事件

 

5. monkey约束类命令

 

adb shell monkey -p <allowed-package-name> <event-count> 测试一个或多个包名,每个-p对应一个包。

adb shell monkey -p <main-category> <event-count> 测试一个或多个类别。

 

6. monkey调试类命令

 

adb shell monkey --dbg-no-events <event-count> 监视应用程序所调用的包之间的转换

adb shell monkey --hprof <event-count> 在事件序列前后立即生成profiling report

adb shell monkey --ignore-crashes <event-count> monkey在应用崩溃或异常后继续发送事件直到计数完成

adb shell monkey --ignore-timeouts <event-count> monkey在任何超时错误发生后继续发送事件直到计数完成

adb shell monkey --ignore-security-exceptions <event-count> monkey在应用权限错误发生后继续发送事件直到计数完成

adb shell monkey --kill-process-after-error <event-count> monkey因为应用发生错误而停止时,将会通知系统停止发送错误进程

adb shell monkey --monitor-native-crashes <event-count> 让监视并报告monkey运行时Android系统native code的崩溃事件

adb shell monkey --wait-dbg <event-count> 暂停执行中的monkey,直到有调试器与它连接

 

7. monkey API

 

轨迹球事件

DispatchTrackball(long downTime,  long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int device, int edgeFlags)

输入字符串事件

DispatchString(String text)

点击事件

DispatchPointer(long downTime,  long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int device, int edgeFlags)

启动应用

LaunchActivity(String pkg_name, String cl_name)

等待事件

UserWait(long sleeptime)

按下按键

DispatchPress(int keyCode)

长按按键

LongPress(int keyCode)

发送按键

DispatchKey(long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode)

 

 

 TestBird



收藏(0)0
查看评分情况

全部评分

此主贴暂时没有点赞评分

总计:0

回复分享
TestBird  于   2017-02-09 14:28 重新编辑过

共有0条评论

    • 慧星的那一夜
    • MK
    • 药师
    • IT宅男
    • mr jack
    • YUI
    • Mr ken
    • cappuccino
    • 课课家技术团队1
    • 选择版块:

    • 标题:

    • 内容

    • 验证码:

    • 标题:

    • 内容

    • 选择版块:

    移动帖子x

    移动到: