Official Document URL: file: // D:/tool/new_androidsdk/docs/tools/help/monkey.html
The basic syntax is:
$ adb shell monkey [options]<event-count>
With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send events to any (and all) packages installed on your target. here is a more typical command line, which will launch your application and send 500 pseudo-random events to it:
$ adb shell monkey -p your.package.name -v 500
Example 1: Enter the command in shell (to test com. hskj. memo example): monkey-p com. hskj. memo-s 100-v 500 (test com. hskj. memo package, random sorting by seed of 100 <set seed to facilitate the next test of the same event, no
The starting position of the test is the same, for example, the starting position is desktop or a status of an Activity. The test result is displayed at the third level, that is, the most detailed display)
Example 2: follow these steps to troubleshoot a Monkey test error:
1. Find the monkey and the trigger of the error:
2. View the event actions before a monkey error, and manually execute this action.
3. If not, run the monkey-p com. hskj. memo-s 100-v -- throttle 2000 500 command.
Example 3:
1. Set the pause for each action for 5 seconds or another time period until an error occurs. At this time, you can have more time to view the execution process of each action.
2. After an error is found, change the source code. After the error is changed, perform the same seed value and the same starting position to test the same event again.
3. If the error does not occur again, perform another SEED value test. It is a stable enough program until it has been proven to be correct.
------------------------------ Monkey test tool --------------------------------------------------------------
Monkey Test Tool
Source: http://blog.163.com/bobile45@126/blog/static/9606199220124882231634/
1. Introduction to Monkey testing
Monkey testing is an automated test method on the Android platform. Using the Monkey program, you can simulate the user's touch screen, sliding Trackball, and buttons to press the program on the device.
Force Testing detects how long an exception occurs in the program.
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) 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;
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. Operation Sequence
Although columns are 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, so this operation sequence is pseudo-
Host;
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, even if the application crashes, the Monkey still sends the event, directly
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, even if an ANR error occurs in the application,
Monkey still sends events 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, even if a license error occurs in the application,
Monkey still sends events 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, and 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%;
------------------------------------------ This is the official document ------------------------------------------------------
UI/Application Exerciser Monkey
The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. you can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Overview
The Monkey is a command-line tool that you can run on any emulator instance or on a device. it sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.
The Monkey pair des a number of options, but they break down into four primary categories:
- Basic configuration options, such as setting the number of events to attempt.
- Operational constraints, such as restricting the test to a single package.
- Event types and frequencies.
- Debugging options.
When the Monkey runs, it generates events and sends them to the system. It alsoWatchesThe system under test and looks for three conditions, which it treats specially:
- If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to any other packages, and blocks them.
- If your application crashes or es any sort of unhandled exception, the Monkey will stop and report the error.
- If your application generatesApplication not respondingError, the Monkey will stop and report the error.
Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.
Basic Use of the Monkey
You can launch the Monkey using a command line on your development machine or from a script. because the Monkey runs in the emulator/device environment, you must launch it from a shell in that environment. you can do this by prefacingadb shell
To each command, or by entering the shell and entering Monkey commands directly.
The basic syntax is:
$ adb shell monkey [options]<event-count>
With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send events to any (and all) packages installed on your target. here is a more typical command line, which will launch your application and send 500 pseudo-random events to it:
$ adb shell monkey -p your.package.name -v 500
Command Options Reference
The table below lists all options you can include on the Monkey command line.
Category |
Option |
Description |
General |
--help |
Prints a simple usage guide. |
-v |
Each-v on the command line will increment the verbosity level. level 0 (the default) provides little information beyond startup notification, test completion, and final results. level 1 provides more details about the test as it runs, such as individual events being sent to your activities. level 2 provides more detailed setup information such as activities selected or not selected for testing. |
Events |
-s <seed> |
Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events. |
--throttle <milliseconds> |
Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible. |
--pct-touch <percent> |
Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen .) |
--pct-motion <percent> |
Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event .) |
--pct-trackball <percent> |
Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click .) |
--pct-nav <percent> |
Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device .) |
--pct-majornav <percent> |
Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key .) |
--pct-syskeys <percent> |
Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls .) |
--pct-appswitch <percent> |
Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity () call, as a way of maximizing coverage of all activities within your package. |
--pct-anyevent <percent> |
Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth. |
Constraints |
-p <allowed-package-name> |
If you specify one or more packages this way, the Monkey willOnlyAllow the system to visit activities within those packages. if your application requires access to activities in other packages (e.g. to select a contact) you'll need to specify those packages as well. if you don't specify any packages, the Monkey will allow the system to launch activities in all packages. to specify multiple packages, use the-p option multiple times-one-p option per package. |
-c <main-category> |
If you specify one or more categories this way, the Monkey willOnlyAllow the system to visit activities that are listed with one of the specified categories. if you don't specify any categories, the Monkey will select activities listed with the category Intent. CATEGORY_LAUNCHER or Intent. CATEGORY_MONKEY. to specify multiple categories, use the-c option multiple times-one-c option per category. |
Debugging |
--dbg-no-events |
When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. for best results, combine with-v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. this provides an environment in which you can monitor package transitions invoked by your application. |
--hprof |
If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~ 5 Mb) files in data/misc, so use with care. See Traceview for more information on trace files. |
--ignore-crashes |
Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. if you specify this option, the Monkey will continue to send events to the system, until the count is completed. |
--ignore-timeouts |
Normally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. if you specify this option, the Monkey will continue to send events to the system, until the count is completed. |
--ignore-security-exceptions |
Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. if you specify this option, the Monkey will continue to send events to the system, until the count is completed. |
--kill-process-after-error |
Normally, when the Monkey stops due to an error, the application that failed will be left running. when this option is set, it will signal the system to stop the process in which the error occurred. note, under a normal (successful) completion, the launched process (es) are not stopped, and the device is simply left in the last state after the final event. |
--monitor-native-crashes |
Watches for and reports crashes occurring in the Android system native code. If -- kill-process-after-error is set, the system will stop. |
--wait-dbg |
Stops the Monkey from executing until a debugger is attached to it. |
Cannot T as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see the Content License.
About Android | Legal | Support