|[Date: 2010-11-08]||Source: Linux Community Meditation||[Font: Big Small]|
The focus of this week is also on the Android monkey test some of the relevant knowledge, but also carried out a preliminary operation and testing. The learning materials are organized as follows:
Monkey is a command-line tool that can be run in the emulator or in the actual device. It sends a pseudo-random user event stream to the system, enabling stress testing of the application under development. Monkey includes many options, which are broadly divided into four categories:
· Basic configuration options, such as setting the number of events to try.
· Run constraint options, such as setting to test only a single package.
· The event type and frequency.
· Debugging options.
When the monkey is running, it generates events and sends them to the system. At the same time, monkey also monitors the system under test, and carries out special treatment for the following three cases:
· If Monkey is qualified to run on one or several specific packages, it will monitor and block attempts to move to other packages.
· If the application crashes or receives any runaway exceptions, the monkey will stop and error.
· If the application produces an error that the application does not respond to (application not responding), Monkey will stop and make a mistake.
According to the different levels of feedback you have selected, you can also see their execution process reports and generated events in monkey.
Monkey Basic Usage
You can start monkey by developing a command line or script on the machine. Because the monkey is running in an emulator/device environment, it must be started with the shell in its environment. You can do this by adding the ADB shell to each command, or you can enter the monkey command directly after entering the shell. The basic syntax is as follows:
$ adb shell monkey [options]
If you do not specify Options,monkey will start in a no-feedback mode and send events to all packages installed in the target environment. The following is a more typical command-line example that launches a specified application and sends 500 pseudo-random events to it:
$ adb shell Monkey-p your.package.name-v 500
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 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.
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.
Adjusts the percentage of touch events (a touch event is a down-up event that occurs in a single location on the screen).
Adjusts 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).
Adjusts the percentage of track events (the trajectory event consists of one or more random movements, sometimes accompanied by clicks).
Adjusts the percentage of the basic navigation event (the navigation event consists of the up/down/left/right from the direction input device).
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)
Adjusts 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).
Adjusts the percentage of startup Activity. In a random interval, Monkey executes a startactivity () call as a way to maximally cover all Activity in the package.
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.
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.
If you specify one or more categories with this parameter, Monkey will only allow the system to start Activity that is listed by a category in these categories. If you do not specify any categories, Monkey will select the Activity:Intent.CATEGORY_LAUNCHER or Intent.category_monkey listed in the following categories. To specify multiple categories, you need to use multiple-c options, and each-c option can only be used for one category.
Set this option, Monkey will perform the initial boot, enter into a test Activity, and no further events will be generated. For best results, combine it with-V, one or several package constraints, and a non-0 value that keeps Monkey running for 30 seconds or longer, providing an environment to monitor conversions between packages called by the application.
Set this option to generate the profiling report immediately before and after the Monkey event sequence. This will generate a large file (~5MB) in the Data/misc, so use it with care.
Typically, Monkey stops running when an application crashes or any runaway exception occurs. If this option is set, Monkey will continue to send events to the system until the count is complete.
Typically, Monkey stops running when an application has any time-out errors, such as the application not responding dialog box. If this option is set, Monkey will continue to send events to the system until the count is complete.
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.
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.
Monitor and report crash events for native code in your Android system. If--kill-process-after-error is set, the system will stop running.
Stop Monkey in execution until there is a debugger connected to it.
Getting started with Android testing---Monkey test