移动APP测试之Monkey Test运用

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

当然对于移动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 ,是指随机发送事件数

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

让monkey运行指定monkey脚本,为测试脚本名,是指循环次数。

adb shell monkey -s

可以重复之前的随机操作,-s后接随机数的生成器的seed值。

adb shell monkey --throttle

表示每个事件之间的固定延迟事件,时间的单位为ms,若后面不接时间,monkey将不会延迟

事件百分比

adb shell monkey --ptc-touch

设定触摸事件的百分比

adb shell monkey --ptc-motion

设定动作事件的百分比

adb shell monkey --ptc-trackball

设定轨迹球事件的百分比

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

adb shell monkey --ptc-majornav

设定主要导航事件的百分比

adb shell monkey --ptc-syskeys

设定按键事件的百分比

adb shell monkey --ptc-appswitch

设定启动事件的百分比

adb shell monkey --ptc-anyevent

其他类型事件的百分比,包括keypress、不常用button以及其他未提及事件

5. monkey约束类命令

adb shell monkey -p

,测试一个或多个包名,每个-p对应一个包。

adb shell monkey -p

,测试一个或多个类别。

6. monkey调试类命令

adb shell monkey --dbg-no-events

监视应用程序所调用的包之间的转换

adb shell monkey --hprof

在事件序列前后立即生成profiling report

adb shell monkey --ignore-crashes

让monkey在应用崩溃或异常后继续发送事件直到计数完成

adb shell monkey --ignore-timeouts

让monkey在任何超时错误发生后继续发送事件直到计数完成

adb shell monkey

--ignore-security-exceptions 让monkey在应用权限错误发生后继续发送事件直到计数完成

adb shell monkey --kill-process-after-error

让monkey因为应用发生错误而停止时,将会通知系统停止发送错误进程

adb shell monkey --monitor-native-crashes

让监视并报告monkey运行时Android系统native code的崩溃事件

adb shell monkey --wait-dbg

暂停执行中的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, Stringcl_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)

你可能感兴趣的:(移动APP测试之Monkey Test运用)