Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the purpose of the monkey command

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what the function of the monkey command is. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Monkey is a command line tool in Android. Monkey commands send pseudo-random user event streams (such as key input, touch screen input, gesture input, etc.) to the system to realize the stress test of the application under development.

A brief introduction to Monkey

Monkey is a tool that comes with SDK. Monkey is a command-line tool in Android that can be run in a simulator or in a real device. It sends pseudo-random user event streams (such as key input, touch screen input, gesture input, etc.) to the system to realize the stress test of the application under development. Monkey testing is a fast and effective method to test the stability and robustness of software.

The tool is used for stress testing. Then the developer combines the log printed by monkey and the log printed by the system to analyze the problems in the test.

Characteristics of Monkey testing:

In the Monkey test, all events are randomly generated without anyone's subjectivity.

1. The object tested is only the application package, which has some limitations.

2. The event data stream used in Monky testing is random and cannot be customized.

3. The object, number, type and frequency of MonkeyTest can be set.

II. The basic usage of Monkey

The basic syntax is as follows:

$adb shell monkey [options]

If you do not specify options,Monkey, it will start in no feedback mode and send events arbitrarily to all packages installed in the target environment. The following is a more typical command-line example that starts the specified application and sends it 500 pseudorandom events:

$adb shell monkey-p your.package.name-v 500

When you start an application using the android automated testing tool monkeyrunner, you need to fill in the package name and launched Activity of the program under test. There are two ways to view the application package name package and entry activity name:

Method 1: use aapt / / aapt is a tool that comes with sdk, in the sdk\ builds-tools\ directory

1. Take the ES file browser as an example, change to the aapt.exe directory on the command line to execute: aapt dump badging E:\ apk\ es3.apk

two。

Note: aapt.exe can be found in the android sdk directory search, and apktool can be downloaded if not available.

3. An example of Monkey testing

Through this example, we can understand the steps of Monkey testing and how to know which applications can be tested with Monkey.

Under Windows (Note: step 2-4 is to see which application packages we can test, but omitted):

1. Start an emulator of Android through eclipse

2. Enter: adb devices on the command line to check the device connection

C:\ Documents and Settings\ Administrator > adb devices

List of devices attached

Emulator-5554 device

3. On the premise that the device is connected, enter: adb shell on the command line to enter the shell interface

C:\ Documents and Settings\ Administrator > adb shell

#

4. View the application package under the data/data folder. Note: all the application packages we can test are under this directory

C:\ Documents and Settings\ Administrator > adb shell

# ls data/data

Ls data/data

5. MonkeyTest with com.android.calculator2 as the object

# monkey-p com.android.calculator2-v 500

Where-p represents the object package-v represents the level of feedback

While running, the applications in Emulator are constantly switching screens.

Depending on the selected level of feedback, you can also see its execution process reports and generated events in Monkey.

Use the monkey help command to view the command parameters

C:\ Users\ chenfenping > adb shell monkey-help

Usage: monkey [- p ALLOWED_PACKAGE [- p ALLOWED_PACKAGE]...]

[- c MAIN_CATEGORY [- c MAIN_CATEGORY]...]

[--ignore-crashes] [--ignore-timeouts]

[--ignore-security-exceptions]

[--monitor-native-crashes] [--ignore-native-crashes]

[--kill-process-after-error] [--hprof]

[--pct-touch PERCENT] [--pct-motion PERCENT]

[--pct-trackball PERCENT] [--pct-syskeys PERCENT]

[--pct-nav PERCENT] [--pct-majornav PERCENT]

[--pct-appswitch PERCENT] [--pct-flip PERCENT]

[--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]

[--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]

[--pkg-whitelist-file PACKAGE_WHITELIST_FILE]

[--wait-dbg] [--dbg-no-events]

[--setup scriptfile] [- f scriptfile [- f scriptfile]...]

[--port port]

[- s SEED] [- v [- v].]

[--throttle MILLISEC] [--randomize-throttle]

[--profile-wait MILLISEC]

[--device-sleep-time MILLISEC]

[--randomize-script]

[--script-log]

[--bugreport]

[--periodic-bugreport]

COUNT

1 parameter:-p

For constraint restrictions, use this parameter to specify one or more packages (Package, that is, App). After the package is specified, monkey will only allow the system to start the specified APP, and if the package is not specified, it will allow the system to start all APP.

* specify a package: adb shell monkey-p cn.emoney.acg 10

* specify multiple packages: adb shell monkey-p cn.emoney.acg-p cn.emoney.wea-p cn.emoney.acg 100

* do not specify package: adb shell monkey 100

2 parameter:-v

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

Log level Level0

Example adb shell monkey-p cn.emoney.acg-v 100

Describe the default values and provide only a small amount of information such as startup prompts, test completion, and final results

Log level Level 1

Example adb shell monkey-p cn.emoney.acg-v-v 100

The description provides a more detailed log, including information about each event sent to Activity

Log level Level 2

Example adb shell monkey-p cn.emoney.acg-v-v-v 100

Describes the most detailed logs, including Activity information selected / unselected in the test

3 Parameter:-s

Used to specify the value of the pseudo-random number generator, and if the seed is the same, the sequence of events generated by the two Monkey tests is the same.

Monkey test 1:adb shell monkey-p cn.emoney.acg-s 10 100

Monkey test 2:adb shell monkey-p cn.emoney.acg-s 10 100

The effect of the two tests is the same, because the simulated sequence of user actions (a series of operations, that is, a sequence of operations in a certain order) is the same.

4 Parameter:-- throttle

Used to specify the delay between user actions (that is, events) in milliseconds

Adb shell monkey-p cn.emoney.acg-- throttle 5000

5 Parameter:-- ignore-crashes

Used to specify whether Monkey stops running when the application crashes (Force& Close error). If you use this parameter, even if the application crashes, Monkey will still send events until the event count is complete.

Adb shellmonkey-p cn.emoney.acg-- ignore-crashes 1000

Even if the program crashes during testing, Monkey will continue to send events until the number of events reaches 1000

Adb shellmonkey-p cn.emoney.acg 1000

During the test, if the acg program crashes, Monkey will stop running

6 Parameter:-- ignore-timeouts

Used to specify whether Monkey stops running when an ANR (Application No Responding) error occurs in the application. If you use this parameter, Monkey will still send events until the event count is complete, even if an ANR error occurs in the application.

Adb shellmonkey-p cn.emoney.acg-- ignore-timeouts 1000

7 Parameter:-- ignore-security-exceptions

Used to specify whether Monkey stops running when an application has a license error (such as certificate license, network license, etc.). If you use this parameter, Monkey sends events until the event count is complete, even if a license error occurs in the application.

Adb shellmonkey-p cn.emoney.acg-- ignore-security-exception 1000

8 Parameter:-- kill-process-after-error

Used to specify whether to stop the application from running when an error occurs. If you specify this parameter, the application stops running and remains in its current state when an error occurs

(note: the application is only quiescent in the state when an error occurs, and the system does not end the application's process.)

Adb shellmonkey-p cn.emoney.acg-- kill-process-after-error 1000

9 Parameter:-- monitor-native-crashes

Native code that specifies whether to monitor and report application crashes.

Adb shellmonkey-p cn.emoney.acg-- monitor-native-crashes 1000

Parameter:-- pct- {+ event category} {+ event category percentage}

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

Example:

-- pct-touch {+ percentage}

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

Adb shell monkey-p cn.emoney.acg-- pct-touch 10 100

-- pct-motion {+ percentage}

Adjust the percentage of action events (action events consist of a down event, a series of pseudo-random events, and a up event somewhere on the screen)

Adb shell monkey-p cn.emoney.acg-- pct-motion 20 1000

-- pct-trackball {+ percentage}

Adjust the percentage of track events (track events consist of one or more random movements, sometimes accompanied by clicks)

Adb shell monkey-p cn.emoney.acg-- pct-trackball 30 1000

-- pct-nav {+ percentage}

Adjust the percentage of "basic" navigation events (navigation events consist of up/down/left/right from direction input devices)

Adb shell monkey-p cn.emoney.acg-- pct-nav 40 1000

-- pct-majornav {+ percentage}

Adjust the percentage of "primary" navigation events (these navigation events usually trigger actions in the graphical interface, such as 5-way keyboard middle button, fallback button, menu button)

Adb shell monkey-p cn.emoney.acg-- pct-majornav 50 1000

7. Output monkeylog

When running monkey or trying to catch the export of program log, sometimes it will prompt: cannot create D:monkeytest.txt: read-only file system

Why sometimes can and sometimes not?

Later, it is found that it is different from the usage habit, one is to enter the adb shell first and then to use the command, the other is to enter the command directly.

After entering adb shell, using the command will fail.

Correct method: do not enter shell when exiting shell or executing commands

C:\ Documents and Settings\ Administrator > adb shell monkey-p package name

-v 300 > e:\ text.txt

Entering adb shell is equivalent to entering the root of linux. You do not have permission to create files in it.

5. Analysis of Monkey test results. Preliminary analysis method

After an error occurs in the Monkey test, the general steps for error detection are as follows:

1. Find out what went wrong in monkey

2. Check some event actions in Monkey before the error, and execute the action manually

3. If the above steps cannot be found, you can use the previous monkey command to execute it again, and note that the threshold value should be the same-- repeat.

General analysis of test results:

1. ANR problem: search for "ANR" in the log

2. Crash problem: search the log for "Exception" Force Close

This is the end of the article on "what is the function of the monkey command". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report