APP stress tests Monkey Tools - Getting Started

Monkey pressure testing tools Introduction

About a .Monkey test

Monkey Android platform testing is a test automation means to pressure test the program on a device simulation program Monkey user touches the screen, the slide Trackball, operation keys and the like, how long will the program detects abnormality occurs.

II. Environment to build

1. JDK installation, JDK to download codecs installed; (JDK jre and mounted in the same file) after installation generating two folders, folder as shown in JAVA:

2.JAVA set up environment variables:

My Computer → Right-click on the new property →→ environment variables

- need to find Path in the System variables, click on Edit and click OK; add% JAVA_HOME% \ bin

After the addition was complete, the press opens win + r key operation, input cmd

In cmd input or java -version javac

If the JAVA version information appears, indicating that environment variable to success

3.Android SDK Tools installed, choose to install their own computer systems.

  • sdk (64-bit operating system):
  • sdk (32-bit operating system):

Mounting path may change (large disk space, after downloading the tool will be relatively large Andrews: tens G), after installation in the following figure:

After installation, the first Android set environment variables with the same JAVA

First New ANDROID_HOME environment variables

In the Path edit join% ANDROID_HOME% \ tools;% ANDROID_HOME% \ platform-tools;

Verify that the configuration is successful, in cmd, type: adb, appear following figure shows success

Three Monkey Test Command [Note: to ensure adequate phone memory, or can not test]

Enter a space adb shell:

Appears error: device not found, said Ming Anzhuo device is not found, then you can use the phone connected to the computer, you must open the phone's USB mode, the driver must have a phone installed on your computer, even after the equipment, we enter adb shell command

Enter the command to perform the operation: pm list packages get to the phone to install all the package name;

pm list packages -3 package name can be found directly inside the mobile phone third-party software;

The figure command has completed, then we can execute monkey command:

monkey -p com.example.ting_app -v 1000 (the package name, for example)

This command execution means 1000 to a random user simulation operation, com.example.ting_app to the name of the installation package,

NOTE: output log at the PC side, need to exit the shell; windows return to the previous command: Exit; example: adb shell monkey -p com.example.fx_app -s 88.TXT

You can also set not rely on USB print log

In performing monkey tests, if the monkey test logs stored in the phone's sdcard or other directory, continue monkey in the case of the final with an ampersand, you can do the monkey USB connection test command. Such as: monkey -p com.android.mms -s 100 --throttle 1000 -v -v -v 15000> /mnt/sdcard/monkey_test.txt&

IV. Parameter parsing command

* -P parameters for constraints, using this parameter specifies one or more packets (the Package, i.e. App). Designation

After the package, Monkey will only allow the system to start the specified APP. If no packet, Monkey will allow the system to start APP all devices.

* Specify a package: adb shell monkey -p com.ting.Weather 100

说明:com.htc.Weather为包名,100是事件计数(即让Monkey程序模拟100次随机用户事件)。

* 指定多个包:adb shell monkey -p com.ting.Weather –p com.ting.pdfreader  -p com.ting.photo.widgets 100

* 不指定包:adb shell monkey 100

说明:Monkey随机启动APP并发送100个随机事件。

* 要查看设备中所有的包,在CMD窗口中执行以下命令:

 >adb shell

  #cddata/data

  #ls或

>adb shell

#pm list packages

* --throttle <milliseconds> 在事件之间插入固定延迟。通过这个选项可以减缓Monkey 的执行速度。如果不指定该选项,Monkey将不会被延迟,事件将尽可能快地被产成。命令中的380就是延迟时间,单位为毫秒。

* -v  命令行的每一个-v 将增加反馈信息的级别。Level 0( 缺省值) 除启动提示、测试完成和最终结果之外,提供较少信息。Level 1 提供较为 详细的测试信息,如逐个发送到Activity 的事件。Level 2 提供更加详细的设置信息,如测试中被选中的或未被选中的 Activity 事 件。

* -s <seed>  伪随机数生成器的 seed 值。如果用相同的seed 值再次运行Monkey ,它将生成相同的事件序列。命令中的300000 代表monkey event 执行的次数,3500表示Seed值(影响随机事件的发生顺序)

* C:\monkey_log.txt 指将Monkey 的log存在PC端的C盘根目录下。

* 关于Monkey的其它命令,可以通过adb shell monkey来查看:

Monkey测试结果分析
一. 初步分析方法:
Monkey测试出现错误后,一般的差错步骤为以下几步:
1、 找到是monkey里面的哪个地方出错
2、 查看Monkey里面出错前的一些事件动作,并手动执行该动作
3、 若以上步骤还不能找出,可以使用之前执行的monkey命令再执行一遍,注意seed值要一样
一般的测试结果分析:
1、 ANR问题:在日志中搜索“ANR”
2、 崩溃问题:在日志中搜索“crash”

3、其他问题:在日志中搜索“Exception”
4、详细分析monkey日志:
将执行Monkey生成的log,从手机中导出并打开查看该log;在log的最开始都会显示Monkey执行的seed值、执行次数和测试的包名。

首先我们需要查看Monkey测试中是否出现了ANR或者异常,具体方法如上述。
然后我们要分析log中的具体信息,方法如下:
查看log中第一个Switch,主要是查看Monkey执行的是那一个Activity,譬如下面的log中,执行的是com.tencent.smtt.SplashActivity,在下一个swtich之间的,如果出现了崩溃或其他异常,可以在该Activity中查找问题的所在。
:Switch:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.tencent.smtt/.SplashActivity;end
  // Allowing start of Intent {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]cmp=com.tencent.smtt/.SplashActivity } in package com.tencent.smtt
在下面的log中,Sending Pointer ACTION_DOWN和Sending Pointer ACTION_UP代表当前执行了一个单击的操作;
Sleeping for 500 milliseconds这句log是执行Monkey测试时,throttle设定的间隔时间,每出现一次,就代表一个事件。
SendKey(ACTION_DOWN) //KEYCODE_DPAD_DOWN 代表当前执行了一个点击下导航键的操作;
Sending Pointer ACTION_MOVE 代表当前执行了一个滑动界面的操作。
:Sending Pointer ACTION_DOWN x=47.0 y=438.0
:Sending Pointer ACTION_UP x=47.0 y=438.0
Sleeping for 500 milliseconds
:SendKey (ACTION_DOWN): 20 //KEYCODE_DPAD_DOWN:SendKey (ACTION_UP): 20 //KEYCODE_DPAD_DOWN
Sleeping for 500 milliseconds
:Sending Pointer ACTION_MOVE x=-2.0 y=3.0
:Sending Pointer ACTION_MOVE x=4.0 y=-3.0
:Sending Pointer ACTION_MOVE x=-5.0 y=-3.0
:Sending Pointer ACTION_MOVE x=3.0 y=4.0
:Sending Pointer ACTION_MOVE x=-4.0 y=1.0
:Sending Pointer ACTION_MOVE x=-1.0 y=-1.0
:Sending Pointer ACTION_MOVE x=-2.0 y=-4.0
如果Monkey测试顺利执行完成,在log的最后,会打印出当前执行事件的次数和所花费的时间;// Monkey finished代表执行完成。Monkey执行中断,在log的最后也能查看到当前已执行的次数。Monkey执行完成的log具体如下:
Events injected: 6000
:Dropped: keys=0 pointers=9 trackballs=0 flips=0
## Network stats: elapsed time=808384ms (0ms mobile, 808384ms wifi, 0msnot connected)
// Monkey finished

补充:monkey的高级参数:(最好加上,因为不加的遇到崩溃问题monkey会停止运行)

--ignore-crashes    忽略崩溃和异常

--ignore-timeouts  忽略超时

--ignore-security-exception     忽略程序发生的许可错误

--monitor-native-crashes      监视崩溃时的本地代码

例如:

adb shell monkey -p com.example.ting_app --throttle 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -s 1000  -v -v -v 180000 1 > C:\Monkey_log1.txt  

注意事项:

1、手机屏幕设置一直亮着,不可关闭,防止手机进入锁屏状态

2、尽量不插卡

3、保证手机USB可以传输数据,而不是只充电状态

4、开发修复完问题后,需要重新回归测试,验证是否修改OK,此时,需要使用上一次跑的monkey测试中的seed值做回归测试。

 

 

Guess you like

Origin www.cnblogs.com/tingting1202/p/11684086.html