APP Stability Test Artifact Monkey Full Analysis

Monkey is a program that runs on an emulator or device and generates a stream of pseudo-random user events (such as clicks, taps, or gestures) as well as many system-level events. You can use Monkey to stress test applications under development in a randomized and repeatable fashion.

 

01. Overview

Monkey is a command-line tool that can be run on any emulator instance or device. It sends a stream of pseudo-random user events into the system to stress test the application software you are developing.

Monkey contains many options, mainly divided into the following four categories:

  • Basic configuration options, such as setting the number of events to try.

  • Operational constraints, such as restricting test objects to a single package.

  • Event type and frequency.

  • Debug options.

When the Monkey runs, events are generated and sent to the system. It also monitors the system under test and looks for three special conditions:

  • If you have restricted Monkey to run in one or more specific packages, it monitors and blocks attempts to switch to any other package.

  • If the app crashes or receives any unhandled exceptions, Monkey stops and reports the error.

  • If the application generates an "Application Not Responding" error, Monkey stops and reports the error.

Depending on the level of detail you choose, you'll also see reports on Monkey's progress and generated events.

02. Basic usage of Monkey

You can start Monkey using the command line on your development computer, or from a script. Since Monkey runs in an emulator/device environment, you have to start it via shell from that environment. You can do this by prepending each command with adb shell, or by going directly to the shell and entering the Monkey command.

The basic syntax is as follows:

adb shell monkey [options] <event-count>

If no options are specified, Monkey starts in silent (non-verbose) mode and sends events to any (and all) packages installed on the target. Here's a more typical command line that starts your app and sends it 500 pseudorandom events:

adb shell monkey -p your.package.name -v 500

03. Command option reference

1. Conventional 

Output a simple usage guide:

–help

Each -v on the command line increases the verbosity level.

  • Level 0 (the default) only provides notifications for startup, test completion, and final results.

  • Level 1 provides more details about the test as it runs, such as individual events sent to your Activity.

  • Level 2 provides more detailed setup information, such as which Activities are or are not selected for testing.

–v

2. Event

The seed value for the pseudorandom number generator. If you re-run Monkey with the same seed value, it will generate the same sequence of events.

-s

Inserts a fixed delay time between events. You can use this option to slow down Monkey. If not specified, there is no delay and events are generated as soon as possible.

-throttle

Adjust the percentage of touch events. (A touch event is a press/release event on a single location on the screen.)

-pct-touch

Adjust the percentage of motion events. (Action events include a press event at a location on the screen, a sequence of pseudo-random actions, and a release event.)

-pct-motion

Adjusts the percentage of trackball events. (A trackball event consists of one or more random actions, sometimes followed by a click.)

-pct-trackball

Adjust the percentage of "basic" navigation events. (Navigation events include up/down/left/right, as input for directional input devices.)

-pct-nav 

Adjust the percentage of "primary" navigation events. (These navigation events typically result in actions in the interface, such as the middle button of the 5-way pad, the return key, or the menu key.)

-pct-majornav

Adjust the percentage of "system" key events. (These keys are usually reserved for system use, such as "Home", "Back", "Initiate Call", "End Call", or "Volume Control".)

-pct-syskeys

Adjust the percentage of activity starts. Monkey initiates startActivity() calls at random intervals to maximize coverage of all Activities in the package.

-pct-appswitch

Adjust the percentages for other types of events. This includes all other types of events such as key presses, other less commonly used buttons on the device, etc.

-pct-anyevent 

3. Constraints

If you specify one or more packages this way, Monkey will only allow the system to access Activities within those packages.

  • If your app needs to access activities in other packages (such as selecting contacts), you also need to specify those packages.

  • If no package is specified, Monkey will allow the system to start activities in all packages.

  • To specify multiple packages, use the -p option multiple times, one for each package.

-p

If you specify one or more categories in this way, Monkey will only allow the system to access activities listed in one of the specified categories.

If no category is specified, the Monkey selects activities listed in the Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY categories.

To specify multiple categories, use the -c option multiple times—one -c option for each category.

-c

4. Debugging

When specified, the Monkey will initially launch into the test Activity, but will not generate any other events. For best results, use -v with one or more package constraints and a non-zero limit so that Monkey runs for 30 seconds or longer. This provides an environment in which you can monitor package conversion operations invoked by your application.

-dbg-no-events

If this option is set, analysis reports are generated immediately before and after the sequence of Monkey events. This will generate large (about 5Mb) files under data/misc, so use with caution

-hprof

Normally, Monkey will stop when the application crashes or encounters any kind of unhandled exception. If this option is specified, Monkey will continue sending events to the system until the count is complete.

-ignore-crashes

Normally, Monkey will stop when the application encounters any kind of timeout error, such as an "Application Not Responding" dialog. If this option is specified, Monkey will continue sending events to the system until the count is complete.

-ignore-timeouts

Normally, Monkey will stop when an app encounters any kind of permission error (for example, if it tries to start an Activity that requires a specific permission). If this option is specified, Monkey will continue sending events to the system until the count is complete.

-ignore-security-exceptions

Normally, when Monkey stops running due to an error, the faulty application will keep running. When this option is set, it instructs the system to stop the process in which the error occurred. Note that in case of normal (successful) completion, the started process will not be stopped and the device will only be in the last state after the final event.

-kill-process-after-error

Monitor and report crashes that occur in Android system native code. If --kill-process-after-error is set, the system will stop.

-monitor-native-crashes

Prevents Monkey from executing until a debugger is attached to it.

-wait-dbg


meager strength

Finally: The following complete software testing video learning tutorial has been sorted out and uploaded. Friends can get it for free if they need it [100% free guarantee]

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can help you too!

 软件测试技术交流群社:110685036(里面还有工作内推机会,毕竟我们是关系社会。)

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.



 

How to obtain interview documents:

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/130152609