Introducing the Monkey Test

1. Introduction to
Monkey Test Monkey test is a means of automated testing on the Android platform. The Monkey program simulates the user's operations such as touching the screen, sliding the Trackball, and pressing buttons to perform stress tests on the programs on the device, and detect how long the program will be abnormal.

2. Introduction of Monkey program
1) Monkey program comes with Android system and is written in Java language. The storage path in Android file system is: /system/framework/monkey.jar;
2) Monkey.jar program is composed of a file named The shell script of "monkey" starts the execution. The storage path of the shell script in the Android file system is: /system/bin/monkey; in this way, you can execute Monkey by executing in the CMD window: adb shell monkey {+command parameter} tested. 

3. Simple help of Monkey command
To of Monkey command, execute the command in CMD:
adb shell monkey –help
  


4. Introduction to Monkey command parameters
1) Parameters: -p
parameter -p is used to constrain restrictions, use this The parameter specifies one or more packages (Package, ie App). After specifying the
package , Monkey will only allow the system to launch the specified APP. If no package is specified, Monkey will allow the system to launch all apps on the device.
* Specify a package: adb shell monkey -p com.htc.Weather 100
Description: com.htc.Weather is the package name, and 100 is the event count (ie, let the Monkey program simulate 100 random user events).
* Specify multiple packages: adb shell monkey -p com.htc.Weather -p com.htc.pdfreader -p com.htc.photo.widgets 100
* Do not specify a package: adb shell monkey 100
 Description: Monkey randomly starts the APP and sends 100 random events.
* To view all the packages in the device, execute the following command in the CMD window:
  >adb shell
  #cd data/data
  #ls

2) Parameter: -v
is used to specify the level of feedback information (the level of information is the level of detail of the log), a total of There are 3 levels, and the corresponding parameters are shown in the following table:
Log level Level 0 
Example adb shell monkey -p com.htc.Weather –v 100
Description default value, only a small amount of information such as startup prompt, test completion and final result is provided

Log level Level 1
example adb shell monkey -p com.htc.Weather -v -v 100
Description Provide more detailed logs, including information about each event sent to the Activity

Log level Level 2
example adb shell monkey -p com.htc. Weather -v -v -v 100
Description The most detailed log, including the selected/unselected Activity information in the test

3) Parameters: -s
Used to specify the seed value of the pseudo-random number generator. If the seed is the same, the sequence of events generated by the two Monkey tests is also the same.
* Example:
 Monkey test 1: adb shell monkey -p com.htc.Weather –s 10 100
   Monkey test 2: adb shell monkey -p com.htc.Weather –s 10 100
   The effect of both tests is the same because the simulation The user operation sequence (a series of operations composed of each operation in a certain sequence, that is, a sequence) is the same. Although the operation sequence is randomly generated, as long as we specify the same Seed value, the random operation sequence generated by the two tests can be guaranteed to be exactly the same, so this operation sequence is pseudo-random;

4) Parameters: --throttle < milliseconds>
is used to specify the delay between user operations (ie events), in milliseconds;
* Example: adb shell monkey -p com.htc.Weather --throttle 3000 100
  
5) Parameters: --ignore-crashes
is used to specify when Whether Monkey stops running when the application crashes (Force & Close error). If this parameter is used, even if the application crashes, Monkey will still send events until the event count is complete.
* Example 1: adb shell monkey -p com.htc.Weather --ignore-crashes 1000
  Even if the Weather program crashes during the test, Monkey will continue to send events until the number of events reaches 1000;
* Example 2: adb shell monkey -p com.htc.Weather 1000
  During testing, if the Weather program crashes, Monkey will stop running.


6) Parameters: --ignore-timeouts
is used to specify whether Monkey will stop running when an ANR (Application No Responding) error occurs in the application. If this parameter is used, even if the application has an ANR error, Monkey will still send events until the event count is complete.

7) Parameters: --ignore-security-exceptions
is used to specify whether Monkey should stop running when the application has permission errors (such as certificate permission, network permission, etc.). If this parameter is used, even if the application has a license error, Monkey will still send events until the event count is complete.

8) Parameters: --kill-process-after-error
is used to specify whether to stop the running of the application when an error occurs. If this parameter is specified, when an error occurs in the application, the application stops running and remains in the current state (Note: the application is only in the state when the error occurs, and the system does not end the process of the application).

9) Parameters: --monitor-native-crashes
is used to specify whether to monitor and report the native code that the application crashes.

10) Parameters: --pct-{+event category} {+event category percentage}
is used to specify the percentage of the number of events of each category (in the Monkey event sequence, the number of events of this type accounts for the percentage of the total number of events)

Parameters:
use Description:
Example:

--pct-touch {+percent}
adjust the percentage of touch events (a touch event is a down-up event that occurs at a single location on the screen)
adb shell monkey -p com.htc.Weather --pct-touch 10 1000

--pct-motion {+percent}
Adjust percentage of motion events (motion events consist of a down event somewhere on the screen, a series of pseudo-random events, and an up event) adb shell monkey -p com.htc.Weather --pct-motion 20 1000

--pct-trackball {+percent}
Adjust the percentage of track events (track events consist of one or several random movements, sometimes accompanied by clicks)
adb shell monkey -p com.htc.Weather --pct-trackball 30 1000
--pct-nav {+percent}

Adjust percentage of "basic" navigation events (navigation events consist of up/down/left/right from directional input devices)
adb shell monkey -p com.htc .Weather --pct-nav 40 1000

--pct-majornav {+percent}
Adjust the percentage of "primary" navigation events (these navigation events usually trigger actions in a GUI, e.g. middle key on a 5-way keyboard, back key, menu key)
adb shell monkey -p com.htc.Weather --pct-majornav 50 1000

--pct-syskeys {+percent}
Adjust the percentage of "system" keystroke events (these keys are usually reserved and used by the system, such as Home, Back, Start Call, End Call and volume control keys)
adb shell monkey -p com. htc.Weather --pct-syskeys 60 1000

--pct-appswitch {+percent}
Adjust the percentage of startup Activity. At random intervals, Monkey will perform a startActivity() call as a way to maximize coverage of all Activities in the package
adb shell monkey -p com.htc.Weather --pct-appswitch 70 1000

--pct-anyevent {+ Percentage}
adjusts the percentage of other types of events. It includes all other types of events, such as: key presses, other uncommon device buttons, etc.
adb shell monkey -p com.htc.Weather

--pct -anyevent 100 1000* Specify the percentage of multiple types of events:
adb shell monkey -p com.htc.Weather --pct-anyevent 50 --pct-appswitch 50 1000
Note: The total percentage of each event type cannot exceed 100%;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326479592&siteId=291194637