Android app stress test tools-monkey Tool

Source: Internet
Author: User

I. What is Monkey?

Monkey Test is a means of Android automated testing, monkey test itself is very simple, is to simulate the user's key input, touch screen input, gesture input, etc., see how long the device will be abnormal.
Monkey is a command-line tool in Android that can be run in the emulator or in the actual device. It sends pseudo-random user event streams (such as key input, touch input, gesture input, etc.) to the system, enabling stress testing of the application under development. Monkey testing is a fast and effective method to test the stability and robustness of the software.

Two.Characteristics of Monkey1, the test object is only the application package, there are certain limitations.
2. The event stream data stream used by the Monky test is random and cannot be customized.
3, can set the Monkeytest object, the number of events, type, frequency, etc.


Three. Basic usage of Monkey
The use of configuration parameters for the Monkey tool. As follows:



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 .All activity in the system (not actually all activity, but the activity that contains intent.category_launcher or Intent.category_monkey).

For example: a simple monkey command:
$ adb shell monkey-p your.package.name-v


When you run the command, you can see that the specified app is running erratically. (e.g. mobile e-tax)


However, in order to ensure the complete number of tests in the work, we generally do not exit the stress test immediately when an error occurs and need to continue, but also to print the relevant logs. such as the Monkey Test command is as follows:
adb shell monkey-p cn.com.servyou.xj-s--ignore-crashes--ignore-timeouts--monitor-native-crashes-v-V 10000 > E:\monkey_log\java_monkey_log.txt
Monkey-Action package:CN.COM.SERVYOU.XJ
Seed value of the resulting time series: 500
Ignores program crashes, ignores timeouts, monitors local program crashes, and details Level 2 (-v-v), resulting in 10,000 events.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are often many options available in the actual situation.
Four categories-common options, event options, constraint options, debugging options
1: Common options
--help: Printing Help information
- V: Specifies the level of detail for printing information, a-V adds a level, and the default level is 0.

2: Event Options
- S: Specifies that random event seed values are generated, and the same seed values produce the same sequence of events. such as:-S
--throttle: The time interval after each event-reducing the pressure on the system (if not specified, the system will send the sequence of events as soon as possible). such as:--throttle
--pct-touch: Specifies the percentage of touch events, such as:--pct-touch 5%, with the following option:
--pct-motion <percent> (Slide event),--pct-trackball <percent> (Trackball event),--pct-nav <percent> (navigation event up/ Down/left/right),--pct-majornav <percent> (main navigation event back key, Menu key),--pct-syskeys <percent> (System key Event Home , back, Startcall, Endcall, Volumecontrol),--pct-appswitch <percent> (switching between activity),--pct-anyevent <percent > (any event)

3: Constraint options
- P: Specifies a valid package (if not specified, it is valid for all package in the system), and one-p corresponds to a valid package, such as:-P com.ckt-p Com.ckt.asura;
-c:activity must contain at least one specified category in order to be activated, otherwise it will not start;


4: Debug Options
--dbg-no-events: Initializes the activated activity, but does not produce any events.
--HPROF: An analysis report is generated immediately before and after the event sequence is specified-the item is generally recommended.
--ignore-crashes: Ignore crashes
--ignore-timeouts: Ignore timeout
--ignore-security-exceptions: Ignoring security exceptions
--kill-process-after-error: Kill the process directly after an error occurs
--monitor-native-crashes: Tracing the crash of a local method
--WAIT-DBG: Know that the debugger is connected to perform the monkey test.


========================================================

AttachedMonkey Command Parameters Introduction
1) Parameter:-P
The parameter-P is used for constraint restrictions, and this parameter specifies one or more packages (the package, or app).
After the package is specified, monkey will only allow the system to launch the specified app.
If you do not specify a package, Monkey will allow the system to boot all apps in the device.
*Specify a package: adb shell monkey-p com.htc.Weather 100
Description: Com.htc.Weather is the package name, 100 is the event count (i.e. let the monkey program simulate 100 random user events).
* Specify multiple packages: adb shell monkey-p com.htc.weather–p com.htc.pdfreader-p com.htc.photo.widgets 100
* Do not specify package: adb shell Monkey 100
Description: Monkey randomly launches the app and sends 100 random events. * To view all packages in the device, execute the following command in the cmd window: >adb Shell #cd data/data #ls

2) Parameter:-V
Used to specify the level of feedback information (the level of information is the verbosity of the log), with a total of 3 levels, respectively, with the corresponding parameters as shown in the following table:
Log levels Level 0
Example adb shell monkey-p com.htc.weather–v 100 describes the default value, providing only small amounts of information such as startup hints, test completion, and final results
Log levels Level 1
Example adb shell monkey-p com.htc.weather–v-v 100 Description Provides a more detailed log, including each event message sent to activity
Log Levels Level 2
Example adb shell monkey-p com.htc.weather–v-v–v 100 describes the most detailed logs, including the selected/unchecked activity information in the test

3) Parameter:-S
Used to specify the seed value of the pseudo-random number generator, and if the seed is the same, the sequence of events produced 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 effect of the two Tests is the same, because the simulated sequence of user actions (a sequence of operations consisting of each operation in a certain order) is the same. The sequence of operations is randomly generated, but as long as we specify the same seed value, we can guarantee that the random sequence of operations generated by the two Tests is exactly the same, so this sequence of operations is pseudo-random;

4) Parameters:--throttle < ms >
Used to specify the delay between user actions (that is, events), in milliseconds;
* Example: adb shell monkey-p com.htc.weather–throttle 3000 100

5) Parameter:--ignore-crashes
Lets you specify whether monkey stops running when the application crashes (force & Close error). If you use this parameter, even if the application crashes, monkey will still send the event until the event count is complete.
* Example 1:ADB shell monkey-p com.htc.Weather--ignore-crashes 1000
Even if the weather program crashes during the test, Monkey continues to send events until the number of events reaches 1000;
* Example 2:ADB Shell monkey-p com.htc.Weather 1000 testing process, if the Weather program crashes, Monkey will stop running.

6) Parameter:--ignore-timeouts
Used to specify whether monkey stops running when an application has a ANR (application No responding) error. If you use this parameter, monkey will still send events until the event count is complete, even if the application has a ANR error.

7) Parameter:--ignore-security-exceptions
Used to specify whether monkey stops running when an application has a licensing error (such as certificate licensing, network licensing, and so on). If you use this parameter, monkey will still send events until the event count is complete, even if the application has a licensing error.

8) Parameter:--kill-process-after-error
Lets you specify whether to stop the application from running when an error occurs. If this parameter is specified, the application stops running and remains in the current state when an application error occurs (note: The application is only stationary in the state where the error occurred and the system does not end the application's process).

9) Parameter:--monitor-native-crashes
Used to specify whether to monitor and report local code for application crashes.

10) Parameters:--pct-{+ Event Category} {+ Event category%}
Used to specify the percentage of events per category (in the Monkey event sequence, the number of such events as a percentage of the total number of events)
Parameters:
Instructions for use:
Example:
--pct-touch {+ percent}
Adjust the percentage of touch events (Touch event is a down-up event that occurs in a single location on the screen)
adb shell monkey-p com.htc.Weather--pct-touch 10 1000
--pct-motion {+ percent}
Adjust 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)
adb shell monkey-p com.htc.Weather--pct-motion 20 1000
--pct-trackball {+ percent}
Adjusts the percentage of track events (track events consist of one or several random movements, sometimes accompanied by clicks) A
DB Shell monkey-p Com.htc.Weather--pct-trackball 30 1000
--pct-nav {+ percent}
Adjust the percentage of basic navigation events (navigation events consist of up/down/left/right from the direction input device)
adb shell monkey-p Com.htc.Weather--pct-nav 40 1000
--pct-majornav {+ percent}
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)
adb shell monkey-p com.htc.Weather--pct-majornav 50 1000
--pct-syskeys {+ percent}
Adjust 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)
adb shell monkey-p com.htc.Weather--pct-syskeys 60 1000
--pct-appswitch {+ percent}
Adjusts the percentage of startup activity. In a random interval, monkey will execute a startactivity () call as a way to maximally cover all activity in the package
adb shell monkey-p com.htc.Weather--pct-appswitch 70 1000
--pct-anyevent {+ percent}
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.
ADB Shell Monkey-p Com.htc.Weather
--pct-anyevent 100 1000* Specify the percentage of multiple types of events:
adb shell monkey-p com.htc.Weather--pct-anyevent--pct-appswitch 50 1000
Note: The total percentage of each event type cannot exceed 100%;

Android app stress test tools-monkey Tool

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.