Usage of the stress testing tool monkey in Android

Source: Internet
Author: User

 

I. Introduction

Monkey is a command line tool that can run in a simulator or a real device. It sends a pseudo-random user event stream to the system to perform stress testing on developing applications. Monkey includes many options, which are roughly divided into four categories:

· Basic configuration options, such as setting the number of attempted events.

· Run constraint options, such as setting to test only one package.

· Event type and frequency.

· Debugging options.

When monkey is running, it generates events and sends them to the system. At the same time, monkey also monitors the system in the test and handles the following three situations:

· If the monkey is limited to one or more specific packages, it will monitor and block operations that attempt to switch to other packages.

· If the application crashes or receives any exceptions that are out of control, the monkey stops and reports an error.

· If the application generates an application not responding error, the monkey will stop and report an error.

Based on the selected feedback information of different levels, you can also see the execution process report and generated events in the monkey.
Ii. Basic monkey usage

You can start monkey through the command line or script on the development machine. Since monkey runs in the simulator/device environment, you must use the shell in the environment to start it. You can add the ADB shell before each command to achieve the goal, or enter the monkey command directly after entering the shell. The basic syntax is as follows:

$ ADB shell monkey [Options]

If no options is specified, monkey starts in non-feedback mode and sends any event to all packages installed in the target environment. The following is a more typical command line example. It starts a specified application and sends 500 pseudo-random events to it:

$ ADB shell monkey-p your. Package. Name-V 500

 

Command Option reference

The following table lists all the options available for the monkey command line.

Category
Option
Description

General
-- Help
List simple usage.

-V
Each-V in the command line will increase the level of feedback information. Level 0 (default) provides less information except the startup prompt, test completion, and final result. Level 1 provides detailed test information, such as events sent to the activity one by one. Level 2 provides more detailed settings, such as the selected or unselected activity in the test.

Event
-S <seed>
The seed value of the pseudo-random number generator. If you run the monkey again with the same seed value, it generates the same event sequence.

-- Throttle <milliseconds>
Insert a fixed delay between events. This option can reduce the execution speed of monkey. If this option is not specified, the monkey will not be delayed and the event will be generated as quickly as possible.

-- PCT-touch <percent>
Adjust the percentage of touch events (a touch event is a down-up event that occurs at a single location on the screen ).

-- PCT-motion <percent>
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 ).

-- PCT-trackball <percent>
Adjust the percentage of track events (track events consist of one or more random moves, sometimes with clicks ).

-- PCT-nav <percent>
Adjust the percentage of "Basic" navigation events (a navigation event consists of up/down/left/right from the input device ).

-- PCT-majornav <percent>
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)

-- PCT-syskeys <percent>
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 ).

-- PCT-Modify witch <percent>
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.

-- PCT-anyevent <percent>
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.

Constraints
-P <allowed-package-Name>
If you use this parameter to specify one or more packages, Monkey only allows the system to start the activity in these packages. If your application needs to access the activity in other packages (for example, select a contact), the packages also need to be specified here. If no package is specified, monkey allows the system to start the activity in all the packages. To specify multiple packages, you need to use multiple-P options. Each-P option can only be used for one package.

-C <main-Category>
If this parameter is used to specify one or more categories, monkey allows the system to start only the activities listed by a category in these categories. If no category is specified, monkey selects the activity listed in the following categories: intent. category_launcher or intent. category_monkey. To specify multiple categories, you need to use multiple-C options. Each-C option can only be used for one category.

Debugging
-- Dbg-no-Events
When this option is set, monkey will start initially, enter a test activity, and no further event will be generated. To get the best result, it is combined with-V, one or more packets, and a non-zero value that keeps the monkey running for 30 seconds or longer, thus providing an environment, monitors the conversion between packages called by applications.

-- Hprof
Set this option to generate a profiling report immediately before and after the monkey event sequence. This will generate a large file (~ 5 MB), so use it with caution.

-- Ignore-crashes
In general, monkey stops running when the application crashes or any runaway exception occurs. If this option is set, monkey continues to send events to the system until the count is complete.

-- Ignore-timeouts
Generally, when an application encounters any timeout error (such as the "Application not responding" dialog box), the monkey stops running. If this option is set, monkey continues to send events to the system until the count is complete.

-- Ignore-security-Exceptions
In general, when an application has a license error (such as starting an activity that requires certain licenses), the monkey stops running. If this option is set, monkey continues to send events to the system until the count is complete.

-- Kill-process-after-Error
Generally, when a monkey stops due to an error, the failed application continues to run. When this option is set, the system will be notified to stop the process with an error. Note that the process ends normally (successfully) and does not stop. The device simply remains in the final state after the event ends.

-- Monitor-native-crashes
Monitors and reports crash events of local code in the Android system. If -- kill-process-after-error is set, the system stops running.

-- Wait-dbg
Stop the running monkey until a debugger is connected to it.

Iii. Instances

$ ADB shell monkey-p your. Package. Name-V 500

 

Use the API provided by Android to test:

Enter ADB shell monkey-P com. example. Android. APIs-V 500

You can see that the screen is constantly switching and the test has started.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.