Test principle and method of "app Automation Test" monkey

Source: Internet
Author: User

Reference: http://blog.csdn.net/io_field/article/details/52189972

first, Monkey Test principle: 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.

Second, test preparation

1, the first need to connect the phone to the PC, test the connection is normal, can be entered in the CMD in the ADB devices to verify;

2, because the test for a specific app package, you need to know the package name of the test package, you can directly ask the development, you can also use the ADB shell PM List packages to list all package names to find

(not sure if the package is installed, you can use the ADB shell PM list packages [options] <INTENT> to confirm that it means listing all packages that include <INTENT>.) e.g. ADB shell pm List Packages Com.taobao.taobao)

3. The command to test a specific app package for adb shell monkey-p <pakage.name>

Three, monkey parameters

General class parameters

1,-help

Role: List Simple usage

Example: adb shell monkey-help can also not write help

2,-V

Action: Each-V on the command line will increase the verbosity of the feedback information.
Level0 (default) provides less information than startup, test completion, and final results.
LEVEL1 provides more detailed test information, such as event information sent individually to the activity.
LEVEL2 provides more setup information, such as selected or unchecked activity information in the test.

The more commonly used is-v-v-V, which is the most detailed information that is typically saved to the specified file for developers to look for in the cause of the bug.

Example: adb shell monkey-v 10

Event class Parameters

1,-S <seed>

Function: The seed value of the pseudo-random number generator. If you run monkey again with the same seed value, the same sequence of events will be generated.

Example: adb shell monkey-s 1483082208904-v 10

2 、--Throttle <milliseconds>

Action: Inserting a fixed time (ms) delay between events, you can use this setting to slow down the monkey, and if you do not specify this parameter, there will be no delay between events, and the event will be generated as quickly as possible.

Note: Common parameters, typically set to 300 milliseconds, are typically set to 300 milliseconds here because of the fastest 300 milliseconds or so of an action event for the actual user operation.

Example: adb shell monkey--throttle 300-v 10

3 、--Pct-touch <percent>

Effect: Adjusts the percentage of touch events. (Touch event refers to a down-up event in the screen that is pressed and lifted at a certain point on the screen)

Note: Commonly used parameters, this parameter is set to adapt to the operation of the current application under test, such as an application 80% is touch, you can set the percentage of this parameter to a corresponding higher percentage.

Example: adb shell monkey--pct-touch 100-v 10

4 、--pct-motion <percent>

Effect: Adjusts the percentage of motion events. (Motion events are made up of a down event on the screen, a series of pseudo-random movement events, and an up event)
Note: Commonly used parameters, it is important to note that moving events are linear sliding
Example: adb shell monkey--pct-motion 100-v 10

5 、--Pct-trackball <percent>
Effect: Adjusts the percentage of rolling ball events. (A rolling ball event consists of one or more random movement events, sometimes accompanied by a click event)
Note: The parameters are not used very often, but now the mobile phone has almost no rolling ball, but the rolling ball event contains a curve sliding event, which can be selected when the program needs curve sliding.
Example: adb shell monkey--pct-trackball 100-v 10

6 、--Pct-nav <percent>
Effect: Adjusts the percentage of basic navigation events. (navigation events consist of events triggered by the up and down buttons on the direction input device)
Note: Infrequently used operations.
Example: adb shell monkey--pct-nav 100-v 10

7 、--Pct-majornav <percent>
Effect: Adjusts the percentage of the primary navigation event. (These navigation events often result in action events in the UI interface, such as the middle key of the 5-way keyboard, the fallback button, the menu button)
Note: Infrequently used operations.
Example: adb shell monkey--pct-majornav 100-v 10

8 、--Pct-syskeys <percent>
Effect: Adjusts the percentage of system events. (These keys are usually reserved for use by the system, such as home, back, Start call, End Call, volume adjustment)
Note: not commonly used.
Example: adb shell monkey--pct-syskeys 100-v 10

9 、--Pct-appswitch <percent>
Effect: Adjusts the percentage of activity startup. (In a random interval, monkey will execute a startactivity () call as a way to maximize the coverage of all activity in the package being tested)
Note: not commonly used.
Example: adb shell monkey--pct-appswitch 100-v 5

Ten 、--Pct-anyevent
Effect: Adjusts the percentage of other events. (This includes all other events, such as keystrokes, other buttons that are not commonly used on the device, etc.)
Note: not commonly used.
Example: adb shell monkey--pct-anyevent 100-v 5

Constraint class Parameters

1,-P <allowed-package-name>
Role: If you specify one or more packages, monkey will only allow access to the activity in those packages. If your application needs to access the activity outside of these packages (such as selecting a contact), you need to specify these packages. If you do not specify any packages, monkey will allow the system to initiate activity for all packages. Specify multiple packages, use multiple-p, and a-p followed by a package name.
Note: Common parameters. (already mentioned in the previous test preparation)
Example: adb shell monkey-p com. Android.browser-v 10

2,-C <main-category>
Role: If you specify one or more categories, monkey will only allow the system to start the activity listed in these specified categories. If you do not specify any categories, MONKEY will select Activity,intent.category_launcher and Intent.category_monkey listed in the Bisceglie category. Specifies that multiple categories use multiple-C, and each-c specifies a category.
Note: not commonly used.

3 、--dbg-no-events
Function: Set this option, monkey will perform an initial boot, enter a test activity, and will not generate the event further. For best results, combine parameter-V, one or more package constraints, and a non-0 value that keeps monkey running for 30 seconds or longer, providing an environment to monitor transitions between packages called by the application.
Note: not commonly used.

4 、--Hprof
Role: Set this option to generate a profilling report before and after the monkey generates the event sequence. Generate large files (~5MB) under the Data/misc path, so use caution.
Note: not commonly used.

5 、--Ignore-crashes
Action: Typically, monkey stops running when an app crashes or an exception occurs. If this key is set, Monkey will continue to send events to the system until the event count is complete.
Note: commonly used.

6 、--Ignore-timeouts
Role: Typically, any time-out errors (such as the "Application Not Responding" dialog box) monkey will stop running, setting this key, Monkey will continue to send events to the system until the event count is complete.
Note: commonly used.

7 、--Ignore-security-exception
Role: Typically, monkey stops running when a program has a licensing error (such as initiating some activity that requires permission) to cause an exception. Setting this, monkey will continue to send events to the system until the event count is complete.
Note: commonly used.

8 、--Kill-process-after-error
Function: Typically, when Monkey is stopped due to an error, the wrong application will continue to be in the running state. Setting this will notify the system to stop the process where the error occurred. Note that the normal (successful) end does not stop the process from starting, and the device simply stays in the final state after the end event.

9 、--Monitor-native-crashes

Role: Monitors and reports on crash events for local code in the Andorid system. If you set--kill-process-after-error, the system will stop running.

Ten 、--wait-dbg

Function: Stop monkey in execution until there is a debugger connected to it.

Test principle and method of "app Automation Test" monkey

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.