Monkey summary (1)
What are monkeys?
Monkey is a command-line tool provided by Google that can run in an emulator or an actual device. It sends pseudo-random user events (such as keystrokes, gestures, touch screen, etc.) to the system to perform stability and stress tests on the software. The Monkey program comes with Android.
Path: /sdcard/system/framework/Monkey.jar
Startup script path: /system/monkey
Configuration of Monkey environment variables
Monkey is started by the adb command, so just configure the adb environment (windows environment as an example)
1. Download the Android SDK and decompress it.
2. Configure the platform-tools and tools directories under the SDK directory to the system environment variables.
3. Open the cmd window and enter adb. The adb help information is configured successfully.
Monkey basic parameters
A complete Monkey command:
adb shell monkey -p cn.microinvestment.weitou --pct-touch 100 --ingore-crashes --throttle 1000 -s 100 -v -v 50
The above is composed of the basic parameters of Monkey. First look at the basic parameters of Monkey:
Classification | options | illustrate |
Basic parameters | --help | Print help information |
-v | The default level of the log information level that Monkey prints to the command line is 0: -v only prints the startup information, the test completion information and the final result information level 2: -v -v Some information executed when printing, such as sending events Level 3:- v -v -v print the most detailed information |
Monkey's Constraint Parameters
Classification | options | illustrate |
Restrictions | -p<list of package names allowed to execute> | If one or several packages are specified with word parameters, Monkey will only allow the system to start the activities in these packages. If your application needs to access activities in other packages (such as selecting a contact), those packages also need to be specified here. If no package is specified, Monkey will allow the system to start the activities in all packages. To specify multiple packages, multiple -p options need to be used, each -p can only be used for one package. |
-c <kind of intent> | If one or several categories are specified with this parameter, Monkey will only allow the system to start activities listed in one of these categories. If you do not specify any category, Monkey will choose the Activity listed in the following categories: Intent.CATEGORY.LAUNCHER or Intent.CATEGORY.MONKEY. To specify multiple categories, multiple -c options need to be used, each -c option can only be used for one category. |
The type and frequency of events sent by the Monkey
event | -s <random number seed> | The seed value of the pseudo-random number generator. If you run Monkey again with the same seed value, it will generate the same sequence of events |
--throttle <type of intent> | Inserts a fixed delay between events. This option can slow down the execution speed of Monkey. If this option is not specified, Monkey will not be delayed, and the event will be executed as soon as possible | |
--pct-touch<percent> | Adjusts the percentage of touch events (a touch event is a down-up event) that occur at a single location on the screen | |
--pct-motion<percent> | Adjust the percentage of motion events (motion events are composed of a down event somewhere on the screen, a series of pseudo-random events, and an up event) | |
--pct-trackball<percent> | Adjust the percentage of track events (a track event consists of one or several random movements, sometimes accompanied by clicks) | |
--pct-nav<percent> | Adjust percentage of "base" navigation time (navigation events consist of up/down/left/right from directional input device) | |
--pct-majornav<percent> | Adjust the percentage of "primary" navigation events (these navigation events usually trigger actions in the GUI, such as the middle key of the 5-way keyboard, the back key, the menu key) | |
--pct-syskeys<percent> | Adjust the percentage of "system" button events (these keys are usually reserved and used by the system, such as Home, Back, StartCall, End Call and volume control keys) | |
--pct-appswitch | Adjust the percentage to start the Activity. At random intervals, Monkey executes a startActivity() call as a way to maximize coverage of all activities in the package | |
--pct-anyevent<percent> | Adjust the percentages for other types of events. It includes all other types of events, such as: key presses, other infrequently used device buttons, etc. | |
--pct-flip PECENT | ||
--pct-pinchzoom PERCENT |
Monkey debugging parameters
Classification | options | illustrate |
debugging | --dbg-no-events | With this option set, the Monkey will perform an initial launch into a test Activity and will not generate further events. It is better to bind it with -v, one or several packages. and a non-zero value that keeps the Monkey running for 30 seconds or more event in combination, thus providing an environment where transitions between packages called by the application can be monitored |
--hprof | Setting this option will generate profiling reports immediately before and after the Monkey event sequence, which will generate large files (~5MB) in data/misc, so use with care | |
--ignore-crashes | Normally, Monkey will stop running when the application crashes or any out-of-control exception occurs. If this option is set, Monkey will continue sending events to the system until the count is complete | |
--ignore-timeouts | Monkey will stop running when the application encounters any timeout errors such as "Application Not Responding" dialogs. If this option is set, Monkey will continue sending events to the system until the count is complete | |
--ingore-security-exceptions | Monkey will stop working when a permission error occurs in the application. If this option is set, Monkey will continue sending events to the system until the count is complete | |
--ingnore-native-crashes | When the application crashes caused by the underlying C/C++ code, Monkey will stop running. Select this, Monkey will continue to send events to the system until the count is complete | |
--monitor-native-crashes | Monitor and report crashes caused by Android C/C++ in the Android system. If --kill-process-after-error is set, the system will stop running | |
--kill-process-after-error | When Monkey stops due to an error, the erroneous application will continue to run. When this option is set, the system will be notified to stop the error-prone process. Note that when Monkey finishes executing normally, it will not close all started applications, and the device still retains the state when Monkey ends | |
--wait-dbq | After starting Monkey, first interrupt its operation and wait for the debugger to attach |
Monkey black and white list
Blacklist: Apps not tested
Whitelist: Only test this part of the application
Note: Blacklist and whitelist cannot be set at the same time
options | illustrate |
--pkg-blacklist-file PACKAGE_BlACKLIST_FILE |
Apk blacklist, block out the apk in the blacklist |
--pkg-whitelist-file PACK_WHITELIST_FILE |
apk whitelist, only test the apk included in the whitelist |
Taking the blacklist as an example, the specific steps are as follows:
1. Find the package of the system and output it to the pkg file of the e disk. adb shell pm list package>e:\pkg.txt
2.将想要加入黑名单的apk的包名放到blacklist.txt里,最后push进设备。adb push e:\blacklist.txt /data/local/tmp/
3.执行Monkey命令。adb shell monkey --pkg-blacklist-file /data/local/tmp/blacklist.txt --throttle 200 200