Android automated stress testing tool: Use of monkey

Source: Internet
Author: User

Monkey stress test
ADB-D shell monkey-p your. Package. Name-V 6000

1. What is monkey?

Monkey is a command line tool in Android and can be run in a simulator or on a real device. It sends a pseudo-random user event stream (such as key input, touch screen input, and gesture input) to the system to perform stress testing on the application being developed. Monkey testing is a fast and effective method to test the stability and robustness of software.

Ii. Monkey features

1. The test object is only an application package and has certain limitations.

2. The event stream data stream used for monky testing is random and cannot be customized.

3. You can set the monkeytest object, event quantity, type, and frequency.

III. Basic usage of monkey

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 1500 pseudo-random events to it:

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

$ Monkey-P (package meaning) specifies the file name-V (number of tests and frequency) number (number of times)

4. One monkey test instance

Through this example, we can understand the monkey test steps and how to know which applications can be tested with monkey.

In Windows (Note: Step 2-4 is to check which application packages can be tested, which can be omitted ):

1. Start an android emulator through eclipse

2. Enter ADB devices in the command line to view the device connection status.

C: \ Documents ents and Settings \ Administrator> ADB Devices

List of devices attached

Emulator-5554 Device

3. If a device is connected, enter ADB shell in the command line to enter the Shell Interface.

C: \ Documents ents and Settings \ Administrator> ADB Shell

#

4. view the application packages in the data/data folder. Note: All the application packages we can test are in this directory.

C: \ Documents ents and Settings \ Administrator> ADB Shell

# Ls data/Data

Ls data/Data

Com. Google. Android. btrouter

Com. Android. providers. Telephony

Com. Android. MMS

Com. Android. providers. downloads

Com. Android. Alibaba clock

Com. Android. Email

Com. Android. providers. Media

Com. Android. Settings

JP. co. omronsoft. openwnn

Com. Android. providers. userdictionary

Com. Android. quicksearchbox

Com. Android. protips

Com. Android. Browser

Com. Android. Launcher

Com. Android. Term

Com. Android. speechrecorder

Com. Android. server. VPN

Com. Android. defcontainer

Com. svox. Pico

Com. Android. customlocale

Com. Android. Development

Com. Android. soundrecorder

Com. Android. providers. DRM

Com. Android. spare_parts

Com. Android. providers. Downloads. UI

Com. Android. Fallback

Com. Android. providers. Applications

Com. Android. netspeed

Com. Android. wallpaper. livepicker

Android. TTS

Com.android.html Viewer

Com. Android. Music

Com. Android. certinstaller

Com. Android. inputmethod. Pinyin

Com. Android. providers. subscribedfeeds

Com. Android. inputmethod. Latin

Com. Android. Gallery

Com. Android. systemui

Com. Android. Contacts

Com. Android. Phone

Com. Android. sdksetup

Com. Android. calculator2

Com. Android. packageinstaller

Com. Android. Camera

Com. Android. providers. Settings

Com. thestore. Main

Com. Android. providers. Contacts

5. Use com. Android. Camera as the object for monkeytest

# Monkey-P com. Android. Camera-V 500

-P indicates the object package-V indicates the number of events.

During the running process, the applications in the emulator are constantly switching the screen.

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

Note: For specific parameter settings, refer:

Http://developer.android.com/guide/developing/tools/monkey.html

5. Stop conditions for monkey testing

Monkey test is automatically stopped in the following three conditions during execution:

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

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

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

It is considered a stable program after multiple monkey tests with different settings.


The following is the original article of the Development document, which also describes other commands in detail ::
Http://developer.android.com/guide/developing/tools/monkey.html:

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 prefacing ADB 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

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-Modify witch <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 will only allow 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 will only allow 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
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.

Related Article

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.