Monkey test_automated test_check whether your application is robust enough. androidmonkey

Source: Internet
Author: User

Monkey test_automated test_check whether your application is robust enough. androidmonkey

In the previous article, we mentioned that the application can automatically capture Crash logs and submit them to the server. If the application has not been strictly tested before the release (some small applications developed by my personal trainer), we will find that many exceptions are obvious errors, I just did not strictly test and ignored it. In fact, android comes with an automated testing tool, Monkey, which can be used to test the robustness of the program.

The monkey test uses socket Communication to simulate users' key input, touch screen input, and gesture input. When a Monkey program is running on a simulator or device, if the user starts a system-level event, such as a click, touch, gesture, or system-level event, it generates a random pulse, therefore, you can use Monkey to load your software by random repetition.

To obtain the simple help provided by the Monkey command, run the following command in CMD:

Adb shell monkey-help

In this way, there are various prompt command parameters.

 

Start testing

Input command adb shell monkey-p jason. wondermap-v 5000

The-p constraint indicates the name of the application package to be tested. You can specify multiple packages. If this parameter is not specified, no restriction is imposed. All applications are tested by default,

-V specifies the level of feedback information (the information level is the log details). There are three levels in total. One v is the default value, and the other-v is the higher level, -v

Next to 5000, specify the number of commands to be tested, that is, the number of inputs to be simulated.


The following is the test result after the command is entered. We can see that seed is randomly generated, and count is 5000.




The Sending is used to simulate the user's key input. The above is a simple test. The more detailed instructions are as follows:

1) parameter:-p

Parameter-p is used to restrict the use of this parameter to specify one or more packages (that is, Apps ). Specify

After the package, Monkey only allows the system to start the specified APP. If no package is specified, Monkey allows the system to start all apps on the device.

* Specify a package: adb shell monkey-p com. htc. Weather 100

Note: com. htc. Weather is the package name, and 100 is the event count (that is, let the Monkey program simulate 100 random user events ).

* Specify multiple packages: adb shell monkey-p com. htc. Weather-p com.htc.pdf reader-p com. htc. photo. widgets 100

* Package not specified: adb shell monkey 100

Note: The Monkey randomly starts the APP and sends 100 random events.

* To view all the packages on the device, run the following command in the CMD window (root permission required ):

> Adb shell

# Cd data/data

# Ls

2) parameter:-v

This parameter is used to specify the level of feedback information (the information level is the log details), which is divided into three levels. The corresponding parameters are shown in the following table:

Log Level Level0

Example adb shellmonkey-p com. htc. Weather-v 100

The default value. Only a small amount of information is provided, such as the startup prompt, test completion, and final result.

 

Log Level 1

Example adb shellmonkey-p com. htc. Weather-v 100

Provides detailed logs, including information about each event sent to the Activity.

 

Log Level 2

Example adb shellmonkey-p com. htc. Weather-v 100

Describe the most detailed logs, including the Activity information selected or not in the test.

 

3) parameter:-s

Specifies the seed value of the pseudo-random number generator. If seed is the same, the event sequence generated 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 effects of the two tests are the same, because the simulated user operation sequence (each operation is composed of a series of operations in a certain sequence, that is, a sequence) is the same.

Although the operation sequence is randomly generated, as long as we specify the same Seed value, we can ensure that the random operation sequence generated by the two tests is identical, therefore, this operation sequence is pseudo-random;

 

4) parameter: -- throttle <millisecond>

Used to specify the latency between user operations (that is, events), in milliseconds;

* Example: adb shell monkey-p com. htc. Weather-throttle 3000 100

5) parameter: -- ignore-crashes

Used to specify whether the Monkey stops running when the application crashes (Force & Close error. If this parameter is used, even if the application crashes, the Monkey still sends the event, directly

 

The event count is complete.

* Example 1: adb shellmonkey-p com. htc. Weather -- ignore-crashes 1000

During the test, even if the Weather program crashes, Monkey continues to send events until the number of events reaches 1000;

* Example 2: adb shellmonkey-p com. htc. Weather 1000

If the Weather program crashes during the test, the Monkey stops running.

 

6) parameter: -- ignore-timeouts

It is used to specify whether the Monkey stops running when the Application has an ANR (Application No Responding) error. If this parameter is used, even if an ANR error occurs in the application,

Monkey still sends events until the event count is complete.

 

7) parameter: -- ignore-security-exceptions

Used to specify whether the Monkey stops running when an application encounters a license error (such as a certificate license or a network license. If this parameter is used, even if a license error occurs in the application,

Monkey still sends events until the event count is complete.

 

8) parameter: -- kill-process-after-error

Specifies whether to stop an application when an error occurs. If this parameter is specified, when an application error occurs, the application stops running and remains in the current State (note:

The application is only static when an error occurs, and the system does not end the process of the application ).

 

9) parameter: -- monitor-native-crashes

Specifies whether to monitor and report local code that crashes the application.

 

10) parameter: -- pct-{+ event category} {+ event category percentage}

Used to specify the percentage of events of each category (in the Monkey event sequence, the percentage of events of this category to the total number of events)

Parameters:

Instructions for use:

Example:

 

-- Pct-touch {+ percentage}

Adjust the percentage of touch events (a touch event is a down-up event that occurs at a single location on the screen)

Adb shell monkey-p com. htc. Weather -- pct-touch 10 1000

 

-- Pct-motion {+ percentage}

Adjust the percentage of Action events (Action events are composed 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 20 1000

 

-- Pct-trackball {+ percentage}

Adjust the percentage of track events (track events consist of one or more random moves, sometimes with clicks)

Adb shell monkey-p com. htc. Weather -- pct-trackball 30 1000


-- Pct-nav {+ percentage}

Adjust the percentage of "Basic" navigation events (navigation events are composed of up/down/left/right from the input device)

Adb shell monkey-p com. htc. Weather -- pct-nav 40 1000

 

-- Pct-majornav {+ percentage}

Adjust the percentage of "Main" navigation events (these events usually lead to operations in the graphic interface, such as the intermediate buttons of the 5-way keyboard, the back button, and the menu button)

Adb shell monkey-p com. htc. Weather -- pct-majornav 50 1000

 

-- Pct-syskeys {+ percentage}

Adjust the percentage of system key events (these keys are usually retained and used 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-average witch {+ percentage}

Adjust the percentage of started Activity. During the random interval, Monkey will execute a startActivity () call as a method to overwrite all the activities in the package to the maximum extent possible.

Adb shell monkey-p com. htc. Weather -- pct-modified witch 70 1000

 

-- Pct-anyevent {+ percentage}

Adjust the percentage of other types of events. It includes all other types of events, such as buttons, other infrequently used device buttons, and so on.

Adb shell monkey-p com. htc. Weather

 

-- Pct-anyevent 100 1000 * specifies the percentage of multiple types of events:

Adb shell monkey-p com. htc. Weather -- pct-anyevent 50 -- pct-Restart witch 50 1000

Note: The percentage of each event type cannot exceed 100%;


Author: jason0539

Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)

Scan the QR code to follow my public account


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.