Android automated testing --monkey summary

What is Monkey

  Monkey is a small Android automated testing tools. Android is mainly used for stress testing, the main purpose is to test whether the app will Crash.

Monkey Features

  As the name suggests, Monkey is a monkey, Monkey test, like a monkey in front of a computer, chaotic keyboarding test. Monkeys do not understand anything, just know Luanqiao. To stress test a 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.

Monkey program introduced

  Monkey is a program that comes with the Android system, written using the Java language. Android storage path in the file system is: /system/framework/monkey.jar;

  Monkey.jar program consists of a Shell script called "monkey" to start the execution, shell script storage path in the Android file system are: / system / bin / monkey;

  Monkey Start: Enter the command in cmd command prompt inside line to start monkey test.

A, Monkey Description:
Monkey is a command-line tool in Android, you can run in the simulator or real device, sending a pseudo-random streams of user events to the system (click, slide, Application switch the screen anyway, the application is closed) to achieve the application being developed stress tests. monkey test is a stable, robust and effective method for the rapid testing for software. Activity done only for testing, do not test for Service.

Second, the quality requirements: the
results of the previous version release (released), Monkey ran out before the crash to be as 0, final release, the total number of Monkey finish should be 25W, there are not allowed nullPointException results appear.

Three, Monkey command parameters:
. 1> -p
for constraints, specified by this parameter or a plurality of packets, after the specified package, Monkey will only allow the specified app starts, if the package is not specified, the system all Monkey app startup .

Example: Specifies a package com.htc.weather -v -p Monkey 1000 
        specify multiple packages Monkey -p com.htc.weather -p com.htc.pdfreader com.htc.photo.widgets -v -p 1000 
        is not specified package Monkey -v 1000

2>  -v

For information level (level of detail of the log) specified feedback, divided into three levels, the higher the level, the more detailed the log.

level 0:

例:monkey -p com.htc.weather -v 1000

level 1:
例:monkey -p com.htc.weather -v -v 1000
level 2:
例:monkey -p com.htc.weather -v -v -v 1000

3> -s

Sequence of events specified pseudorandom number generator seed value, and if the same seed, the two monkey test generation is also the same.

monkey -p com.htc.weather -s 35 -v 1000

4> --throttle (ms)

Develop interval after the end of each event, reduce system pressure. (If you do not specify a sequence of events will be sent as soon as possible)

monkey --throttle 300

5> custom events

--pct-touch: touch event specified percentage, for example: - Touch-PCT . 5 %     , other related:
 -PCT-Motion <Percent> (slip event)
 -PCT-Trackball <Percent> (event trackball ) 
 -PCT-NAV <Percent> (navigation event up / Down / left / right)
 -PCT-majornav <Percent> (main Key navigation event Back, MENU Key) 
 -PCT-the syskeys <Percent> (system key events Home, the Back, StartCall, endCall, VolumeControl)
 -PCT-appswitch <Percent> (switching between Activity)
 -PCT-AnyEvent <Percent> (in any event)

6> Debugging Options

NO----dbg Events: initial start of the activity, but does not generate any events.
- hprof: After specifying the analysis report will be generated immediately before and after the sequence of events to send - the designated generally recommended.
--ignore- crashes: Ignore collapse
 --ignore- timeouts Total: ignore timeout
 --ignore-security- Exceptions and: ignore the security exception
 --kill-Process-after- error: directly kill the process after an error occurred
 --monitor-native- crashes: local method of tracking crashes
 --wait-dbg: know before the implementation of monkey tests connected debugger.

Fourth, the use of the present exemplary embodiment :( Android studio + test environment simulator Nexus_5_API_23)

1 > First configure the Android environment, to use a virtual machine to test it, but also to create a simulator (real test do not control).
2 > into the platform tools, I platform- Tools shown in the following FIG path 
in Android studio comes command line (or cmd), enter the command 

3 > cranking simulator (adb devices execute command to list the device is connected ), install the apk be tested 
first on the apk Platform - Tools folder, execute the command: adb install the file name .apk
 4 > to find the package name of the application's main Activity is located, respectively, execute the following command:

Ls command is executed after the package name from the list found in the main apk to test the Activity package name.

5> Use the monkey to automate testing

monkey -p package name -v 1000

V. Analysis of test results:

1.

  

2.

3. 

4.

5> test is completed, there is no case of crash and exception appears

6> intermediate test crash occurs or exception, monkey will stop printing-related error messages.

Six, monkey test stop conditions (can also be set in the command appear in these conditions can continue to finish after stopping the number of tests)
1> If the top of the first Monkey running on one or more particular package, then it will attempt to detect operation of its package, and subjected to blocking;

2> if an application crashes or receives any runaway abnormality, Monkey will stop and an error;

3> If the application creates application does not respond (application not responding) error, Monkey will stop with an error.

    通过多次并且不同设定下的Monkey测试才算它是一个稳定性和健壮性足够的程序。

七、为保证测试数量的完整进行,一般不会在发生错误时立刻退出压力测试。monkey 测试命令如下
adb shell monkey -p 包名 -s 500 --ignore-crashes --ignore-timeouts --monitor-native-crashes -v -v -v 10000

八、把log导出到本地
这里分为两种情况:
1.如果我们没有进入到shell则直接执行命令:
adb shell monkey -p 包名 -s 500 --ignore-crashes --ignore-timeouts --monitor-native-crashes -v -v -v 10000 > E:\monkey_log\test1.txt

2.
如果已经进入adb shell,正确的导出步骤:(在前边我们执行完adb shell命令之后,进入shell命令相当于进入Linux的root下面,没有权限在里面创建文件。)
执行exit命令退出shell

然后执行adb shell monkey -p 包名 -s 500 --ignore-crashes --ignore-timeouts --monitor-native-crashes -v -v -v 10000 > E:\monkey_log\test1.txt

 

Guess you like

Origin www.cnblogs.com/jiangzhaowei/p/11353569.html