您的位置:首页 > 其它

Monkey测试工具

2016-03-23 11:23 260 查看
本文你将获得的东西:

1,了解Monkey是什么?

2,如何用Monkey测试App的性能?

一,Monkey介绍

Monkey是一款Google提供的一个用于稳定性与压力测试的命令行工具。拟用户的按键输入,触摸屏输入,手势输入等,看设备多长时间会出异常。

二,Monkey用法

1,启动

/*PC启动
* [option] 测试条件(下面会做详细说明)
* <count> 测试次数
*/
adb shell monkey [option] <count>


2,保存运行日志

Monkey允许用户可以把运行日志打印到本地或者手机上。

//保存在手机上
adb shell monkey [option] <count> > /mnt/sdcard/monkey.txt

//保存在电脑上
adb shell monkey [option] <count> > D:\monkey.txt

/*还可以根据类别来保存(其中保存的位置也可已换成手机上的位置)
* 1>打印正确的信息
* 2>打印错误的信息
*/
adb shell monkey [option] <count> 1> D:\monkeyRight.txt 2> D:\monkeyErr.txt


3,添加测试约束条件

//-v 打印日志的详细程度,-v参数越多打印信息越详细
adb shell monkey -v -v 100

//-p 指定测试某个包
adb shell monkey -p com.android.email 100

//-c 指定测试某个意图,在Manifest中Category参数
adb shell monkey -c com.android.examlple.MONKEY

//-s 随机种子数,需要复现某个测试效果。
adb shell monkey -s 1234 100

//--throttle 每次操作后延迟300毫秒
adb shell monkey --throttle 300 100

//--randomize-throttle 随机延迟,必须与--throttle一起用
adb shell monkey --throttle 300 --randomize-throttle 50 100


4,调试参数

//--dbg-no-events 仅测试打开应用
adb shell monkey --dbg-no-events 100

//--ignore-crashes 忽略crash异常
adb shell monkey --ignore-crashes 100

//--ignore-timeouts 忽略ANR异常
adb shell monkey --ignore-timeouts 100

//--ignore-security-exception 忽略权限许可异常
adb shell monkey --ignore-security-exception 100

//--ignore-native-crashes 忽略本地底层错误
adb shell monkey --ignore-native-crashes 100

//--monitor-native-crashes 忽略Android底层错误
adb shell monkey --monitor-native-crashes 100


5,黑白名单的添加

//--pkg-blacklist-file PACKAGE_BLACKLIST_FILE 该文件下的包不测试
adb shell monkey --pkg-blacklist-file D:\black.txt

//--pkg-whitelist-file PACKAGE_WHITELIST_FILE 仅测试该文件中的包
adb shell monkey --pkg-whitelist-file D:\white.txt


下面命令是查询应用的包名,并保存到本地

//查看手机端的包名
adb shell pm list packages

//把列表保存到D盘的pkg.txt文件中
adb shell pm list packages > D:\pkg.txt


6,Monkey测试策略介绍

//case 1:整机测试,而不测试拨号盘应用,忽略所有错误,次数100万次。
adb shell monkey --ignore-crashes --ignore--timeouts --pkg-blacklist-file /data/local/tmp/blacklist.txt -v -v 1000000

//case 2:测试计算器30万次,随机种子为100,随机延迟0-1秒,忽略所有错误
adb shell monkey -p com.android.calculator2 -s 100 --throttle 1000 --randomize-throttle --ignore-crashes --ignore-timeouts -v -v 300000

//case 3:测试计算机,触摸时间30%,其他按键50%,错误停止,延迟200
adb shell monkey -p com.android.calculator2 --throttle 200 --pct-touch 30 --pct-anyevent 50 -v -v 100000

//case 4:对计算器进行旋转压力测试,事件延时2秒,10万次
adb shell monkey -p com.android.calculator2 --pct-rotation 100 --throttle 2000 100000

//case 5:仅对整机的应用开启测试,事件延时5秒,10万次
adb shell monkey --pct-appswitch 100 --throttle 5000 10000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: