Android and android Official Website
Monkey Test
Address: http://blog.csdn.net/caroline_wendy
1. Introduction to Monkey testing
Monkey TestIt is a means of automated testing on the Android platform. It uses the Monkey program to simulate the user's touch screen, sliding Trackball, and buttons.
Operation to test the pressure on the program on the device, and detect how long the program will be abnormal.
II. Introduction to the Monkey program 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) The Monkey. 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;
Run the Monkey test:
Adb shell monkey {+ command parameter}
Iii. Monkey Command help
To obtain the simple help provided by the Monkey command, run the following command in CMD:
adb shell monkey –help
Iv. Monkey command parameters 1) parameters:-p
Parameter-p is used to restrict the use of this parameter to specify one or more packages (that is, Apps ).
After a package is specified, 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.pdfreader -p com.htc.photo.widgets 100
* Do not specify the package:
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) parameters:-v is used to specify the level of feedback information (the information level is the log details). There are three levels in total. The corresponding parameters are shown in the following table:
Log Level 0, for 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 1, for example:
adb shell monkey -p com.htc.Weather –v -v 100
Description: provides detailed logs, including information about each event sent to the Activity.
Log Level 2, for example:
adb shell monkey -p com.htc.Weather –v -v –v 100
Note: The most detailed log contains the Activity information selected or not in the test.
Modify the log storage location so that it is stored in the mobile phone. If an exception occurs, pull enters the computer:
2>/sdcard/error.txt 1>/sdcard/info.txt
PULL command:
adb shell pull /sdcard/error.txt Desktop/error.txt
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:
adb shell monkey -p com.htc.Weather –s 10 100adb 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,
This ensures that the random operation sequence generated by the two tests is identical, so the operation sequence is pseudo-random;
4) parameter: -- throttle <millisecond>
This parameter is used to specify the latency between user operations (events) in milliseconds. For example:
adb shell monkey -p com.htc.Weather --throttle 3000 100
Note: The delay is 3 seconds and the execution is 100 times;
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 is used to specify whether the Monkey stops running when an ANR (Application No Responding) error occurs in the Application.
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.
The usage is similar to ignoring the crash: -- ignore-crashes
7) parameter: -- ignore-security-exceptions is used to specify whether the Monkey stops running when an application has 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 is used to specify 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 is used to specify whether to monitor and report local code for application crash.
10) parameter: -- pct-{+ event category} {+ event category percentage} is used to specify the percentage of events of each category (in the Monkey event sequence, percentage of events of this type 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 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%;
Command:
monkey -p com.lenovo.ideafriend --ignore-crashes --ignore-timeouts --ignore-native-crashes --pct-touch 30 -s 1 -v -v --throttle 200 100000 2>/sdcard/error.txt 1>/sdcard/info.txt
5. Forcibly terminate the Monkey program: 1) ps command
Find the process of uiautomator and open the command line window and enter:
adb shell ps | grep monkey
The first number returned is the monkey process number.
2) kill command to end the process and continue to input
Adb shell kill [process number just found]
This method can also be used to end other processes and other applications.