1. Introduction to Monkey testing
Monkey testing is a means of automated testing on the Android platform. The Monkey program simulates the user's touch screen, sliding Trackball, buttons, and other operations to perform stress testing on the program on the device, how long will the program be abnormal.
Ii. Monkey program Introduction
1) The Monkey program is provided by the Android system and written in Java. The storage path in the Android file system is/system/framework/monkey. jar;
2) Monkey. the jar program is started and executed by a Shell script named "monkey". The storage path of the shell script in the Android file system is/system/bin/monkey; in this way, you can perform the monkey test by executing: adb shell Monkey {+ command parameter} in the CMD window.
Iii. Simple Monkey Command help
To obtain the simple help provided by the Monkey command, run the following command in CMD:
Adb shell monkey-help
4. Introduction to Monkey Command Parameters
1) parameter:-p
Parameter-p is used to restrict the use of this parameter to specify one or more packages (that is, Apps ). Specify
After the package, Monkey only allows the system to start the specified APP. If no package is specified, Monkey allows the system to start all apps on the device.
* Specify a package: adb shell monkey-p com. htc. Weather 100
Note: com. htc. Weather is the package name, and 100 is the event count (that is, let the Monkey program simulate 100 random user events ).
* Specify multiple packages: adb shell monkey-p com. htc. Weather-p com.htc.pdf reader-p com. htc. photo. widgets 100
* Package not specified: adb shell monkey 100
Note: The Monkey randomly starts the APP and sends 100 random events.
* To view all the packages on the device, run the following command in the CMD window:
> Adb shell
# Cd data/data
# Ls
2) parameter:-v
This parameter is used to specify the level of feedback information (the information level is the log details), which is divided into three levels. The corresponding parameters are shown in the following table:
Log Level 0
Example adb shell monkey-p com. htc. Weather-v 100
The default value. Only a small amount of information is provided, such as the startup prompt, test completion, and final result.
Log Level 1
Example adb shell monkey-p com. htc. Weather-v 100
Provides detailed logs, including information about each event sent to the Activity.
Log Level 2
Example adb shell monkey-p com. htc. Weather-v 100
Describe the most detailed logs, including the Activity information selected or not in the test.
3) parameter:-S
Specifies the seed value of the pseudo-random number generator. If seed is the same, the event sequence generated by the two monkey tests is 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 effects of the two tests are the same, because the simulated user operation sequence (each operation is composed of a series of operations 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, we can ensure that the random operation sequence generated by the two tests is identical, therefore, this operation sequence is pseudo-random;
4) parameter: -- throttle <millisecond>
Used to specify the latency between user operations (that is, events), in milliseconds;
* Example: ADB shell monkey-P com. HTC. Weather-Throttle 3000 100
5) parameter: -- ignore-crashes
Used to specify whether the monkey stops running when the application crashes (Force & close error. If this parameter is used, Monkey sends an event even if the application crashes until the event count is complete.
* Example 1: ADB shell monkey-P com. HTC. Weather -- ignore-crashes 1000
During the test, even if the weather program crashes, monkey continues to send events until the number of events reaches 1000;
* Example 2: ADB shell monkey-P com. HTC. Weather 1000
If the weather program crashes during the test, the monkey stops running.
6) parameter: -- ignore-timeouts
It is used to specify whether the monkey stops running when the application has an ANR (application No responding) error. If this parameter is used, the monkey sends an event even if an ANR error occurs in the application until the event count is complete.
7) parameter: -- ignore-security-Exceptions
Used to specify whether the monkey stops running when an application encounters a license error (such as a certificate license or a network license. If this parameter is used, the monkey sends an event even if a license error occurs in the application until the event count is complete.
8) parameter: -- kill-process-after-Error
Specifies whether to stop an application when an error occurs. If this parameter is specified, when an application error occurs, the application stops running and remains in the current State (Note: The application is only static when an error occurs, the system does not end the process of the application ).
9) parameter: -- Monitor-native-crashes
Specifies whether to monitor and report local code that crashes the application.
10) parameter: -- PCT-{+ event category} {+ event category percentage}
Used to specify the percentage of events of each category (in the monkey event sequence, the percentage of events of this category to the total number of events)
Parameters:
Instructions for use:
Example:
-- PCT-touch {+ percentage}
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 {+ percentage}
Adjust the percentage of Action events (Action events are composed of a down event, a series of pseudo-random events, and an up event somewhere on the screen) adb shell monkey-p com. htc. weather -- pct-motion 20 20 1000
-- Pct-trackball {+ percentage}
Adjust the percentage of track events (track events consist of one or more random moves, sometimes with clicks)
Adb shell monkey-p com. htc. Weather -- pct-trackball 30 1000
-- Pct-nav {+ percentage}
Adjust the percentage of "Basic" navigation events (navigation events are composed of up/down/left/right from the input device)
Adb shell monkey-p com. htc. Weather -- pct-nav 40 1000
-- Pct-majornav {+ percentage}
Adjust the percentage of "Main" navigation events (these events usually lead to operations in the graphic interface, such as the intermediate buttons of the 5-way keyboard, the back button, and the menu button)
Adb shell monkey-p com. htc. Weather -- pct-majornav 50 1000
-- Pct-syskeys {+ percentage}
Adjust the percentage of system key events (these keys are usually retained 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-average witch {+ percentage}
Adjust the percentage of started Activity. During the random interval, Monkey will execute a startActivity () call as a method to overwrite all the activities in the package to the maximum extent possible.
Adb shell monkey-p com. htc. Weather -- pct-modified witch 70 1000
-- Pct-anyevent {+ percentage}
Adjust the percentage of other types of events. It includes all other types of events, such as buttons, other infrequently used device buttons, and so on.
Adb shell monkey-p com. htc. Weather
-- Pct-anyevent 100 1000 * specifies the percentage of multiple types of events:
Adb shell monkey-p com. htc. Weather -- pct-anyevent 50 -- pct-Restart witch 50 1000
Note: The percentage of each event type cannot exceed 100%;