Monkey Study Notes

Source: Internet
Author: User

Monkey
What is Monkey?
Monkey is a command-line tool in Android, which is actually a tool that comes with the SDK and can be run in the emulator or the actual device.

Second, the purpose of Monkey testing?
Monkey Test is a means of automated testing of Android platform, through the monkey program to simulate the user's key input, touch screen input, gesture input and other operations to test the program on the device stress testing, how long the time of the test program will occur abnormally. The tool is primarily used for stress testing, where developers combine monkey printed logs to solve problems in tests.

Three, the characteristics of Monkey test?
1, the test object is only the application package, there are certain limitations.
2, Monkey test, all the events are randomly generated, without any subjectivity.
3, can set the Monkeytest object, the number of events, type, frequency, etc.

Iv. Use of Monkey
1.monkey Environment Construction
① Download SDK Extract and configure environment variables for tools under SDK
Right-click on "Computer"-"Properties-" Advanced system Settings-"Environment variable-"
Click Path to add "D:\android-sdk-windows\platform-tools" to the variable value, separated from the previous variable value with ";".
② Download and install the JDK and configure the environment variables.

2.monkey command Explanation
Detailed explanations of each command
--HELP lists the simple usage.
-V
Each-V of the command line increases the level of feedback information. Level 0 (default) provides less information than startup prompts, test completion, and end results. Level 1 provides more detailed testing information, such as events sent individually to the activity. Level 2 provides more detailed setup information, such as selected or unchecked activity events in the test
-S
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
Inserts a fixed delay between events. This option slows down the execution speed of the monkey. If this option is not specified, the monkey will not be delayed and the event will be produced as soon as possible.
--pct-touch
Adjusts the percentage of touch events (a touch event is a down-up event that occurs in a single location on the screen).
--pct-motion
Adjusts 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).
--pct-trackball
Adjusts the percentage of track events (the trajectory event consists of one or more random movements, sometimes accompanied by clicks).
--pct-nav
Adjusts the percentage of the basic navigation event (the navigation event consists of the up/down/left/right from the direction input device).
--pct-majornav
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)
--pct-syskeys
Adjusts 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).
--pct-appswitch
Adjusts the percentage of startup activity. In a random interval, monkey executes a startactivity () call as a way to maximally cover all activity in the package.
--pct-anyevent
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. Constraint restrictions
-P
If you specify one or several packages with this parameter, monkey will only allow the system to start the activity in those packages. If your application also needs to access activity in other packages (such as choosing to take a contact), those packages need to be specified at the same time. If you do not specify any packages, monkey will allow the system to start the activity in all packages. To specify multiple packages, you need to use multiple
-P
option, each-p option can only be used for one package.
-C
If you specify one or more categories with this parameter, monkey will only allow the system to start activity that is listed by a category in these categories. If you do not specify any categories, MONKEY will select the Activity:Intent.CATEGORY_LAUNCHER or Intent.category_monkey listed in the following categories. To specify multiple categories, you need to use multiple-c options, and each-c option can only be used for one category of debugging
--dbg-no-events
Set this option, monkey will perform the initial boot, enter into a test activity, and no further events will be generated. For best results, combine it with-V, one or several package constraints, and a non-0 value that keeps monkey running for 30 seconds or longer, providing an environment to monitor conversions between packages called by the application.
--hprof
Set this option to generate the profiling report immediately before and after the monkey event sequence. This will generate a large file (~5MB) in the Data/misc, so use it with care.
--ignore-crashes
Typically, monkey stops running when an application crashes or any runaway exception occurs. If this option is set, Monkey will continue to send events to the system until the count is complete.
--ignore-timeouts
Typically, monkey stops running when an application has any time-out errors, such as the application not responding dialog box. If this option is set, Monkey will continue to send events to the system until the count is complete.
--ignore-security-exceptions
Typically, when an application has a licensing error (such as starting an activity that requires some permission), Monkey will stop running. If this option is set, Monkey will continue to send events to the system until the count is complete.
--kill-process-after-error
Typically, when Monkey is stopped due to an error, the application that is faulted will continue to be in the running state. When this option is set, the system will be notified of the process of stopping the error. Note that the normal (successful) end, and does not stop the process from starting, the device simply stays in the final state after the end event.
--monitor-native-crashes
Monitor and report crash events for native code in your Android system. If--kill-process-after-error is set, the system will stop running. --wait-dbg stops executing the monkey in the execution until there is a debugger connected to it.

A simple example of 3.monkey
adb shell monkey-p net.miju.android.renthousekeeper-s--ignore-crashes--ignore-timeouts-- Ignore-security-exceptions--monitor-native-crashes--throttle 100-v-v 100>e:monkeytest0406.doc
"Command interpretation monkey function of the package: Net.miju.android.renthousekeeper
The seed value of the resulting time series: 100, ignoring program crashes, ignoring timeout, ignoring program errors, monitoring local program crashes, setting delay between events to 100ms, log detail Level 2, generating 100 events, logs written to e-disk in the Monkeytest0406.doc document. 】

Five, Monkey log analysis
: monkey:seed=100 count=100
: AllowPackage:net.miju.android.renthousekeeper
: IncludeCategory:android.intent.category.LAUNCHER
: IncludeCategory:android.intent.category.MONKEY
Selecting main activities from category Android.intent.category.LAUNCHER
+ Using main activity net.miju.android.renthousekeeper.ui.activity.SplashActivity_ (from the package Net.miju.android.renthousekeeper)
Selecting main activities from category Android.intent.category.MONKEY
seeded:100
Event percentages:
0:15.0%/* 0: Touch event percentage, i.e. parameter--pct-touc */
1:10.0%/* 1: Sliding event percentage, i.e. parameter--pct-motion */
2:2.0%/* 2: Scaling event percentage, i.e. parameter--pct-pinchzoom */
3:15.0%/* 3: Trackball event percentage, i.e. parameter--pct-trackball */
4:-0%//4: Screen rotation event percentage, i.e. parameter--pct-rotation */
5:25.0%/* 5: Basic navigation event percentage, i.e. parameter--pct-nav */
6:15.0%/* 6: Main navigation event percentage, i.e. parameter--pct-majornav */
7:2.0%/* 7: System event percentage, i.e. parameter--pct-syskeys */
8:2.0%/* 8:activity start Event percentage, which is the parameter--pct-appswitch */
9:1.0%/* 9: Keyboard rollover event percentage, i.e. parameter--pct-flip */
10:13.0%/* 10: Other event percentage, i.e. parameter--pct-anyevent */
: Switch: #Intent; action=android.intent.action.main;category=android.intent.category.launcher;launchflags= 0x10200000;component=net.miju.android.renthousekeeper/.ui.activity.splashactivity_;end
Allowing start of Intent {Act=android.intent.action.main Cat=[android.intent.category.launcher] cmp= Net.miju.android.renthousekeeper/.ui.activity.splashactivity_} in the package Net.miju.android.renthousekeeper
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (169.0,313.0)
: Sending Touch (ACTION_UP): 0: (148.80295,312.77863)
Sleeping for milliseconds
: Sending Key (action_down): $//Keycode_dpad_right
: Sending Key (ACTION_UP): $//Keycode_dpad_right
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (388.0,576.0)
: Sending Touch (ACTION_UP): 0: (386.73322,583.4074)
Sleeping for milliseconds
: Sending Key (action_down): Keycode_menu
: Sending Key (ACTION_UP): Keycode_menu
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (316.0,315.0)
: Sending Touch (ACTION_UP): 0: (319.49203,320.588)
Sleeping for milliseconds
: Sending Key (Action_down)://Keycode_calculator
: Sending Key (ACTION_UP)://Keycode_calculator
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (112.0,713.0)
: Sending Touch (ACTION_UP): 0: (111.15747,722.57654)
Sleeping for milliseconds
: Sending Key (Action_down)://Keycode_n
: Sending Key (ACTION_UP)://Keycode_n
Sleeping for milliseconds
: Sending Trackball (Action_move): 0: (2.0,0.0)
: Sending Trackball (Action_move): 0: ( -3.0,0.0)
: Sending Trackball (Action_move): 0: (3.0,-1.0)
: Sending Trackball (Action_move): 0: ( -3.0,3.0)
: Sending Trackball (Action_move): 0: ( -1.0,3.0)
: Sending Trackball (Action_move): 0: ( -5.0,-3.0)
: Sending Trackball (Action_move): 0: (1.0,-1.0)
: Sending Trackball (Action_move): 0: (4.0,0.0)
: Sending Trackball (Action_move): 0: (4.0,-3.0)
: Sending Trackball (Action_move): 0: ( -2.0,4.0)
: Sending Touch (Action_down): 0: (318.0,640.0)
: Sending Touch (ACTION_UP): 0: (310.96915,640.89435)
Sleeping for milliseconds
: Sending Key (action_down): $//Keycode_dpad_right
: Sending Key (ACTION_UP): $//Keycode_dpad_right
Sleeping for milliseconds
: Sending Trackball (Action_move): 0: ( -3.0,-3.0)
: Sending Trackball (Action_move): 0: (2.0,-4.0)
: Sending Trackball (Action_move): 0: ( -3.0,-3.0)
: Sending Trackball (Action_move): 0: (1.0,-1.0)
: Sending Trackball (Action_move): 0: ( -2.0,-3.0)
: Sending Trackball (Action_move): 0: (0.0,4.0)
: Sending Trackball (Action_move): 0: (1.0,-5.0)
: Sending Trackball (Action_move): 0: (4.0,0.0)
: Sending Trackball (Action_move): 0: (2.0,-3.0)
: Sending Trackball (Action_move): 0: (1.0,-5.0)
: Sending Touch (Action_down): 0: (359.0,808.0)
: Sending Touch (ACTION_UP): 0: (358.59143,797.18005)
Sleeping for milliseconds
: Sending Key (action_down): 138//Keycode_f8
: Sending Key (ACTION_UP): 138//Keycode_f8
Sleeping for milliseconds
: Sending Key (action_down): Keycode_menu
: Sending Key (ACTION_UP): Keycode_menu
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (296.0,796.0)
: Sending Touch (ACTION_UP): 0: (293.08795,797.0198)
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (378.0,772.0)
: Sending Touch (Action_move): 0: (369.45667,770.2897)
: Sending Touch (Action_move): 0: (365.8055,765.13544)
: Sending Touch (Action_move): 0: (360.95316,750.236)
: Sending Touch (Action_move): 0: (354.3841,736.4228)
: Sending Touch (Action_move): 0: (345.43015,736.0391)
: Sending Touch (Action_move): 0: (336.04175,730.0176)
: Sending Touch (Action_move): 0: (328.16156,717.8114)
: Sending Touch (Action_move): 0: (318.5835,714.58)
: Sending Touch (Action_move): 0: (310.69403,697.46136)
: Sending Touch (ACTION_UP): 0: (305.78015,694.60376)
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (419.0,339.0)
: Sending Touch (ACTION_UP): 0: (412.30893,327.62436)
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (428.0,420.0)
: Sending Touch (action_pointer_down 1): 0: (407.01288,431.44235) 1: (94.0,14.0)
: Sending Touch (action_pointer_up 1): 0: (388.21646,432.3221) 1: (104.55711,0.0)
: Sending Touch (ACTION_UP): 0: (372.00635,443.55457)
Sleeping for milliseconds
: Sending Key (action_down): Keycode_menu
: Sending Key (ACTION_UP): Keycode_menu
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (404.0,82.0)
: Sending Touch (ACTION_UP): 0: (406.27823,70.9695)
Sleeping for milliseconds
: Sending Key (action_down): +//Keycode_explorer
: Sending Key (ACTION_UP): +//Keycode_explorer
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (329.0,397.0)
: Sending Touch (ACTION_UP): 0: (328.2576,388.42487)
Sleeping for milliseconds
: Sending Key (action_down): 198//Keycode_button_11
: Sending Key (ACTION_UP): 198//Keycode_button_11
Sleeping for milliseconds
: Sending Trackball (Action_move): 0: ( -3.0,4.0)
: Sending Trackball (Action_move): 0: (3.0,1.0)
: Sending Trackball (Action_move): 0: (0.0,1.0)
: Sending Trackball (Action_move): 0: ( -3.0,1.0)
: Sending Trackball (Action_move): 0: ( -3.0,-4.0)
: Sending Trackball (Action_move): 0: (2.0,-3.0)
: Sending Trackball (Action_move): 0: ( -3.0,4.0)
: Sending Trackball (Action_move): 0: (3.0,2.0)
: Sending Trackball (Action_move): 0: (4.0,0.0)
: Sending Trackball (Action_move): 0: (2.0,-1.0)
: Sending Key (action_down): Keycode_menu
: Sending Key (ACTION_UP): Keycode_menu
Sleeping for milliseconds
: Sending Key (action_down): +//KEYCODE_DPAD_UP
: Sending Key (ACTION_UP): +//KEYCODE_DPAD_UP
Sleeping for milliseconds
: Sending Touch (Action_down): 0: (177.0,790.0)
: Sending Touch (Action_move): 0: (186.23602,804.68896)
: Sending Touch (Action_move): 0: (194.8559,822.85)
: Sending Touch (Action_move): 0: (198.87949,834.6666)
: Sending Touch (Action_move): 0: (199.37222,837.0604)
: Sending Touch (Action_move): 0: (204.02951,841.66766)
: Sending Touch (Action_move): 0: (206.72707,852.10376)
: Sending Touch (ACTION_UP): 0: (212.26447,854.0)
Sleeping for milliseconds
: Sending Key (Action_down)://Keycode_dpad_left
: Sending Key (ACTION_UP)://Keycode_dpad_left
Events injected:100/**/
: Sending rotation degree=0, Persist=false
:D ropped:keys=26 pointers=73 trackballs=0 flips=0 rotations=0
# # Network stats:elapsed time=2945ms (0ms Mobile, 2945ms WiFi, 0ms not connected)
Monkey finished
View the Monkey log. Preliminary analysis Method:

After the monkey test error occurs, the general error steps are the following:

1. Find out which part of the monkey is wrong

2, check the monkey inside the error before some event action, and manually perform the action

3, if the above steps are not found, you can use the previously executed Monkey command to execute again, note that the seed value is the same

General test Results Analysis:

1. ANR problem (no response problem): Search the Log for "ANR"

2. Crash: Search for "Exception" in the log


Vi. personal problems encountered in the monkey test
1. The following prompt appears when you use the ADB shell command:
* Daemon not running. Starting it now on Port 5037 *
* Daemon started successfully *
Error:device not found
Solution: ① Look under the phone settings USB debugging is turned on?
② Try restarting adb:adb kill-server
ADB start-server
ADB remount
③ Xiaomi phone needs to be in the popup dialog point to determine the allowable debugs.

2, run monkey when you want to catch the program log export, sometimes prompted: Cannot create D:monkeytest.txt:read-only file system
Why can sometimes not be sometimes? Later found to be related to the use of different habits. Sometimes it is the first entry into the ADB shell and then the command, and sometimes the direct command. After entering the ADB shell and then the command will fail, into the ADB shell is equivalent to enter the root of Linux, there is no permission to create files inside. Correct method: Do not enter the shell until you exit the shell or execute the command.

Description: The above contents are for personal study when the information obtained, collated a bit of hope to help the learners to get started.

Monkey Learning notes

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.