Monkey
Monkey是发送伪随机用户事件的工具。
MonkeyScript
MonkeyScript是一组可以被Monkey识别的命令集合,可以完成重复固定的操作。
MonkeyRunner
MonkeyRunner提供了一系列API,可以完成模拟事件及截图操作。
MonkeyRunner APIs
1.MonkeyRunner:用来连接设备或模拟器;
2.MonkeyDevice:提供安装、卸载应用,发送模拟事件;
3.MonkeyImage:完成图像保存及对比的操作。
MonkeyRunner的测试类型:多设备控制、功能测试、回归测试
Monkey与MonkeyRunner的区别:
1.Monkey在adb shell中,生成用户或系统的伪随机事件;MonkeyRunner通过API定义特定命令和事件控制设备。
压力测试结果
1.CRASH:即崩溃,应用程序在使用过程中,非正常退出;
2.ANR(=Application Not Responding)
ADB(=Android Debug Bridge)
1.adb devices:可以查看设备名称;
准备测试环境
1.Android SDK环境;
2.Python环境。
APP压测实践过程
1.在手机开发者选项中,将USB调试选上;
2.确认手机和电脑已经成功连接(adb devices);
3.安装测试APP(adb install package.apk);
4.发送压力指令(adb shell monkey 1000);
5.获取APP包名(adb logcat | grep START);
6.给指定包打压力(adb shell monkey -p package 1000)。
Monkey高级参数的应用
1.throttle参数:指定事件之间的间隔(adb shell monkey -p package --throttle 1000 100);
2.Seed参数:指定随机生成数的seed值(adb shell monkey -s <seed> <event-count>);
3.触摸事件:设定触摸事件百分比;
①adb shell monkey --pct-touch <percent> <event-count>;
②adb shell monkey -v --pct-touch <percent> <event-count>(列出事件执行的详情);
③adb shell monkey -v <event-count>(不设定触摸事件的百分比);
4.动作事件:设定动作事件百分比(adb shell monkey --pct-motion <percent>);
①adb shell monkey --pct-motion <percent> ;
②adb shell monkey --pct-touch <percent> --pct-motion<percent>;
5.轨迹球事件:设定轨迹球事件百分比(adb shell monkey --pct-trackball <perce>);
6.基本导航事件:设定基本导航事件百分比,输入设备的上、下、左、右(adb shell monkey --pct-nav <percent>);
7.主要导航事件:设定主要导航事件百分比,兼容中间键、返回键、菜单按键(adb shell monkey --pct-majornav <percent>);
8.系统导航事件:设定系统导航事件百分比,HOME、BACK、拨号及音量键(adb shell monkey --pct-syskeys <percent>);
9.启动Activity事件:设定启动Activity的事件百分比(adb shell monkey --pct-appswitch <percent>);
10.不常用事件:设定不常用事件的百分比(adb shell monkey --pct-anyevent <percent>);
11.崩溃事件:忽略崩溃和异常(adb shell monkey --ignore-crashes <event-count>);
12.超时事件:忽略超时事件(adb shell monkey --ignore-timeouts <event-count>)。