Take this monkey directive as an example:
A -P com.android.cameraswitch-kill10000
This monkey instruction is test: Generates 10,000 pseudo-random operations (including touch, keystrokes, gestures, etc.) in the camera module.
The following is a brief description of the parameters involved:
-S:
The seed value of the pseudo-random number generator. If you run monkey again with the same seed value, it will generate the same sequence of events.
--throttle:
Inserts a fixed delay between events. This option slows down the execution speed of the monkey. If this option is not specified, the Monkey will not be delayed and the event will be produced as soon as possible.
-P:
If you specify one or several packages with this parameter, monkey will only allow the system to start the activity in those packages. If your application also needs to access activity in other packages (such as choosing to take a contact), those packages need to be specified at the same time. If you do not specify any packages, monkey will allow the system to start the activity in all packages. To specify multiple packages, you need to use multiple-p options, and each-p option can be used for only one package.
--kill-process-after-error:
Typically, when Monkey is stopped due to an error, the application that is faulted will continue to be in the running state. When this option is set, the system will be notified of the process of stopping the error. Note that the normal (successful) end, and does not stop the process from starting, the device simply stays in the final state after the end event.
--ignore-timeouts:
Typically, monkey stops running when an application has any time-out errors, such as the Applicationnot responding dialog box. If this option is set, Monkey will continue to send events to the system until the count is complete.
--ignore-security-exceptions:
Typically, when an application has a licensing error (such as starting an activity that requires some permission), Monkey will stop running. If this option is set, Monkey will continue to send events to the system until the count is complete.
-V:
Each-V of the command line increases the level of feedback information. Level 0 (default) provides less information than startup prompts, test completion, and end results. Level 1 provides more detailed testing information, such as events sent individually to the ActivITy. Level 2 provides more detailed setup information, such as the Activity that was selected or unchecked in the test. The following example uses "-v-v-V", which represents the output of the most verbose monkey log.
- - 800000 >c:\long_radio_report.txt
Monkey
Introduction to Testing
Monkey testing is a means of automated testing of the Android platform, through the monkey program to simulate the user touch screen, sliding trackball, keystrokes and other operations to stress the program on the device, the detection of how long the program will be abnormal.
Monkey
Program Introduction
1) Monkey program is brought by Android system, written in the Java language, the storage path in the Android file system is:/system/framework/monkey.jar;
2) Monkey.jar Program is a shell script named "Monkey" to start execution, shell script in the Android file system storage path is:/system/bin/monkey;
This allows the monkey to be tested by executing in the cmd window: adb shell Monkey {+ command arguments}.
Monkey
simple Help for Commands
To get the simple help that comes with the Monkey command, execute the command in CMD:
ADB Shell Monkey–help
Monkey command parameter Description 1) parameter:-P
The parameter-P is used for constraint restrictions, and this parameter specifies one or more packages (the package, or app). Specified
After the package, Monkey will only allow the system to launch the specified app. If you do not specify a package, Monkey will allow the system to boot all apps in the device.
- Specify a package: adb shell monkey-p com.htc.Weather 100
Description: Com.htc.Weather is the package name, 100 is the event count (i.e. 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 package: adb shell Monkey 100
Description: Monkey randomly launches 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 #ls
2) Parameter:-V
Used to specify the level of feedback information (the level of information is the verbosity of the log), with a total of 3 levels, respectively, with the corresponding parameters as shown in the following table:
Sample adb shellmonkey-p com.htc.weather–v 100
Describe default values, providing only small amounts of information such as startup hints, test completion, and final results
Sample adb shellmonkey-p com.htc.weather–v-v 100
Description provides a more detailed log, including each event message sent to the activity
Sample adb shellmonkey-p com.htc.weather–v-v–v 100
Description of the most detailed log, including the selected/unchecked activity information in the test
3) Parameter:-S
Used to specify the seed value of the pseudo-random number generator, and if the seed is the same, the sequence of events produced 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 effect of the two Tests is the same, because the simulated sequence of user actions (a sequence of operations consisting of each operation in a certain order) is the same. The sequence of operations is randomly generated, but as long as we specify the same seed value, we can guarantee that the random sequence of operations generated by the two Tests is exactly the same, so this sequence of operations is pseudo-random.
4) Parameters:--throttle < ms >
Used to specify the delay between user actions (that is, events), in milliseconds;
Example: adb shell monkey-p com.htc.weather–throttle 3000 100
5) Parameter:--ignore-crashes
Lets you specify whether monkey stops running when the application crashes (force& close error). If you use this parameter, even if the application crashes, monkey will still send the event until the event count is complete.
Example 1:adb shellmonkey-p com.htc.Weather--ignore-crashes 1000
Even if the weather program crashes during the test, Monkey continues to send events until the number of events reaches 1000;
Example 2:ADB shellmonkey-p Com.htc.Weather 1000
During the test, if the weather program crashes, Monkey will stop running.
6) Parameter:--ignore-timeouts
Used to specify whether monkey stops running when an application has a ANR (application No responding) error. If you use this parameter, monkey will still send events until the event count is complete, even if the application has a ANR error.
7) Parameter:--ignore-security-exceptions
Used to specify whether monkey stops running when an application has a licensing error (such as certificate licensing, network licensing, and so on). If you use this parameter, monkey will still send events until the event count is complete, even if the application has a licensing error.
8) Parameter:--kill-process-after-error
Lets you specify whether to stop the application from running when an error occurs. If this parameter is specified, the application stops running and remains in the current state when an application error occurs (note: The application is only stationary in the state where the error occurred and the system does not end the application's process).
9) Parameter:--monitor-native-crashes
Used to specify whether to monitor and report local code for application crashes.
10) Parameters:--pct-{+ Event category}{+ event category%}
Used to specify a percentage of the number of events per category (in the Monkey event sequence, the number of such events as a percentage of the total number of events) parameter:
Instructions for use:
Example:
--pct-touch {+ percent}
Adjust the percentage of touch events (Touch event is a down-up event that occurs in a single location on the screen)
ADB shell Monkey-p Com.htc.weather--pct-touch 10 1000
--pct-motion {+ percent}
Adjust the percentage of action events (an action event consists 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 {+ percent}
Adjusts 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 the percentage of basic navigation events (navigation events consist of up/down/left/right from the direction input device)
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 the graphical interface, such as: 5-way keyboard, Fallback button, menu button)
ADB shell Monkey-p Com.htc.weather--pct-majornav 50 1000
--pct-syskeys {+ percent}
Adjust the percentage of the System key event (these keys are usually reserved for use 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}
Adjusts the percentage of startup activity. In a random interval, monkey will execute a startactivity () call as a way to maximally cover all activity in the package
ADB shell Monkey-p com.htc.weather--pct-appswitch 70 1000
--pct-anyevent {+ percent}
Adjusts the percentage of other types of events. It includes all other types of events, such as keystrokes, other infrequently used device buttons, and so on.
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--pct-appswitch 50 1000
Note: The total percentage of each event type cannot exceed 100%; Bottom of Form
Five
Test Results Analysis
1. Search "ANR": Determine if there is a ANR problem.
2. Search for "Exception":
The following belongs to Monkey's own question. No tube.
: Sending Flip Keyboardopen=false
Got IOException performing Flipjava.io.IOException:write failed:einval (Invalid argument)
Injection Failed
3. System Hang: Check the board is hang off after running.
4. CP Assert: Check if the board has CP assert.
I. Preliminary analysis methods:
After the monkey test error occurs, the general error steps are the following:
1. Find out which part of the monkey is wrong
2, check the monkey inside the error before some event action, and manually perform the action
3, if the above steps are not found, you can use the previously executed Monkey command to execute again, note that the seed value is the same
General test Results Analysis:
1. ANR Problem: Search for "ANR" in the log
2. Crash: Search for "Exception" in the log
Two. Detailed analysis of monkey logs:
The log generated by the monkey will be executed, exported from the phone and opened to view the log, and at the very beginning of log, the seed value, the number of executions, and the package name of the test monkey executed.
First we need to see if there is a ANR or an exception in the monkey test, as described above.
Then we will analyze the specific information in log, as follows:
Look at the first switch in log, primarily to see what monkey is doing with that activity, such as the following log, The execution is com.tencent.smtt.SplashActivity, between the next Swtich, if there is a crash or other exception, you can find the problem in the 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.maincat=[android.intent.category.launcher]cmp= com.tencent.smtt/. Splashactivity} inpackage COM.TENCENT.SMTT
In the following log, sending Pointer Action_down and sending pointeraction_up represent a single click operation currently performed;
Sleeping for -milliseconds This sentence log is the monkey test, throttle set the interval time, each occurrence, represents an event. Sendkey (Action_down)//Keycode_dpad_down represents an operation that currently performs a click-down navigation key;sending Pointer Action_move represents an operation that currently performs a sliding interface. : Sending Pointer Action_down x=47.0y=438.0: Sending Pointer action_up x=47.0y=438.0Sleeping for -Milliseconds:sendkey (action_down): - //Keycode_dpad_down: Sendkey (action_up): - //Keycode_dpad_downSleeping for -milliseconds:sending Pointer action_move x=-2.0y=3.0: Sending Pointer action_move x=4.0y=-3.0: Sending Pointer action_move x=-5.0y=-3.0: Sending Pointer action_move x=3.0y=4.0: Sending Pointer action_move x=-4.0y=1.0: Sending Pointer action_move x=-1.0y=-1.0: Sending Pointer action_move x=-2.0y=-4.0if the monkey test completes successfully, at the end of the log, the number of times the current execution event is printed and the time spent;//Monkey finished represents execution completion. Monkey execution interrupt, at the end of log can also see the current number of executions. Monkey execution completed log is as follows:Events injected:6000:D Ropped:keys=0pointers=9trackballs=0flips=0# # Network stats:elapsed Time=808384ms (0ms Mobile, 808384ms WiFi, 0msnot connected)//Monkey finished
ADB Monkey Usage