Android SDK Command Line Tool Monkey Parameters and Usage Analysis
- 2021-12-09 10:12:22
- OfStack
What is Monkey?
Monkey is a command line tool provided by Android SDK, which can simply and conveniently send pseudo-random user event flow and do pressure (stability) test on Android APP. The main purpose is to test whether app has no response and crashes.
Use of Monkey:
1. Enter the adb shell environment
In the windows environment, enter the DOS interface. In the interface, enter ES22shell to enter the ES24shell environment
(Note: adb shell service uses port 5037. If this port is occupied by other processes, it will not start adb shell normally. It is necessary to close the process occupying this port and restart adb shell)
2. Check the package name
adb shell pm list packages (-f: package name for all applications,-3: package name for non-system installation)
It is necessary to control the execution time of monkey, and the number of times to be executed can be calculated by setting the execution time/event transmission delay.
For example, if you want monkey to run for 24 hours, send one event every 100 milliseconds. 24*60*60*1000/100=864000 (times)
adb shell monkey -p ***-v-v-v-ignore-crashes-ignore-timeoutss-throttle 100 864 000 > D:\monkey.log
Said: monkey will run for 24 hours this time
Monkey Command Parameter Description:
The command parameters of monkey are as follows:
Basic parameters:-v,-s,-p,-throttle, etc
Debugging options:--ignore-crashes, etc
Event type:--pct-touch, etc
(1) Basic parameters
1. The simplest monkey command (monkey 100)
On the device, 100 pseudo-random events are sent for the whole system.
2,-v parameter
Used to specify the feedback information level (the information level is the level of log detail), which is divided into three levels, and the default is-v (corresponding: level0)
-v: Provides only a small amount of information such as startup prompt, test completion prompt and final result.
-v-v: A more detailed log, including information about the time each was sent to activity.
-v-v-v: The most detailed log, including selected/unselected activity information in the test.
Note: When the monkey test is complete, the last 1 must have one: monkey finished ID.
3,-p parameter
When we test, we test for the specific app, so when using monkey test, we need to provide the specific app package name to monkey, and then we need to use the parameter-p. Follow the app package name after-p.
When testing, you can not specify the package name, at this time, monkey will randomly start app on the test equipment for operation; If you only need to test one app, use one-p. If you have multiple app tested at the same time, you can use-p package name 1-p package name 2 to specify the specific app to be tested.
4,-s parameter
Seed value (seed), because monkey sends a pseudo-random stream of events, but if the two seed values are the same, the two monkey tests produce the same sequence of events. (Therefore, the seed value should be recorded during the test to prevent unresponsive and crash, which is not easy to verify.)
Note:-s needs to follow the package name and before the number of times
5.--throttle parameter
Set the delay time (milliseconds) to perform an action-the interval between two events. If this parameter is not specified, events will be generated and sent as quickly as possible.
(2) Debugging options
1,--ignore-crashes
Used to specify whether Monkey stops running when the application crashes. If this parameter is used, even if the application crashes, monkey will still send events until the event count is complete.
2.--ignore-timeouts
Used to specify whether Monkey stops when an ANR (Application No Responding) error occurs in the application. If you use this parameter, ANR will send an event until the event count is complete, even if the application has an ANR error.
3.--ignore-security-exceptionss
Used to specify whether Monkey stops running when an application has a licensing error (such as certificate licensing, network licensing, etc.). If you use this parameter, Monkey will send events until the event count is complete, even if the application has a licensing error.
4.--kill-process-after-error
Used to specify whether to stop the application when an error occurs. If this parameter is specified, the application stops running and remains in its current state when an error occurs (note that the application is only static when the error occurs, and the system does not end the application's process).
5.--monitor-native-crashes
Native code that specifies whether to monitor and report application crashes
6.--hprof
When this option is set, an report larger than 5MB is generated immediately before and after the monkey event sequence and stored at/data/misc
(3) Type of event
There are different types of monkey when sending pseudo-random events. Default random allocation ratio, or you can specify its percentage. If it is not set, it will be-pct-anyevent is 100%, that is, pure random events; If other parameters are configured, but less than 100%, the remaining percentage is also-pct-anyevent events.
The specific event types are:
1: Touch Evence-pct-touch
Adjust the percentage of touch touch events. Touch events refer to one click/lift event in a single position on the screen.
2: Slide screen event-pct-motion (gesture event)
(The gesture event is composed of a press event somewhere on the screen, a series of pseudo-random movements, and a lift event.) That is, a sliding operation, but it is straight and cannot turn.)
3: Trackball-pct-trackball
(Trackball events include one or more random moves, sometimes accompanied by clicks. Trackballs are no longer available on smartphones, just like the arrow keys of the handle.)
4: Rotation (--pct-rotation)
Rotate the screen
5: Navigation-pct-nav
(Navigation events include up, down, left and right, such as the input of direction input devices) The up, down, left and right keys of old mobile phones are not available on smart phones)
6: Main Navigation-pct-majornav
Adjust the percentage of major navigation events (such as intermediate keys, cancel, confirm, or actions of graphical interfaces caused by menus)
7: System Keys-pct-syskeys
Adjust system key events, such as home/back/startcall/endcall and volume control keys
8: app Switch-pct-appswitch
Adjust the percentage of activity booted, and execute one startActivity () method call at random intervals as a method to maximize coverage of all activity of the installation package
9: Keyboard flip (--pct-flip)
10: Random-pct-anyevent
Adjust the percentage of other types of events, such as keystrokes or other less commonly used 1 events