Monkey usage for Performance Testing in Android

Source: Internet
Author: User

Introduction

Monkey is a command line tool that can run in a simulator or a real device. It sends a pseudo-random user event stream to the system to perform stress testing on developing applications. Monkey includes many options, which are roughly divided into four categories:

· Basic configuration options, such as setting the number of attempted events.

· Run constraint options, such as setting to test only one package.

· Event type and frequency.

· Debugging options.

When Monkey is running, it generates events and sends them to the system. At the same time, Monkey also monitors the system in the test and handles the following three situations:

· If the Monkey is limited to one or more specific packages, it will monitor and block operations that attempt to switch to other packages.

· If the application crashes or receives any exceptions that are out of control, the Monkey stops and reports an error.

· If the application generates an application not responding error, the Monkey will stop and report an error.

Based on the selected feedback information of different levels, you can also see the execution process report and generated events in the Monkey.

Monkey usage

You can start Monkey through the command line or script on the development machine. Since Monkey runs in the simulator/device environment, you must use the shell in the environment to start it. You can add the adb shell before each command to achieve the goal, or enter the Monkey command directly after entering the Shell. The basic syntax is as follows:

$ Adb shell monkey [options]

If no options is specified, Monkey starts in non-feedback mode and sends any event to all packages installed in the target environment. The following is a more typical command line example. It starts a specified application and sends 500 pseudo-random events to it:

 

First, switch to the tools directory.
$ Adb shell monkey-p com. buke. caipiao-v 500000

Command Option reference

The following table lists all the options available for the Monkey command line.

Category
Option
Description

General
-- Help
List simple usage.

-V
Each-v in the command line will increase the level of feedback information. Level 0 (default) provides less information except the startup prompt, test completion, and final result. Level 1 provides detailed test information, such as events sent to the Activity one by one. Level 2 provides more detailed settings, such as the selected or unselected Activity in the test.

Event
-S <seed>
The seed value of the pseudo-random number generator. If you run the Monkey again with the same seed value, it generates the same event sequence.

-- Throttle <milliseconds>
Insert a fixed delay between events. This option can reduce the execution speed of Monkey. If this option is not specified, the Monkey will not be delayed and the event will be generated as quickly as possible.

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

-- Pct-motion <percent>
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 ).

-- Pct-trackball <percent>
Adjust the percentage of track events (track events consist of one or more random moves, sometimes with clicks ).

-- Pct-nav <percent>
Adjust the percentage of "Basic" navigation events (a navigation event consists of up/down/left/right from the input device ).

-- Pct-majornav <percent>
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)

-- Pct-syskeys <percent>
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 ).

-- Pct-Modify witch <percent>
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.

-- Pct-anyevent <percent>
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.

Constraints
-P <allowed-package-name>
If you use this parameter to specify one or more packages, Monkey only allows the system to start the Activity in these packages. If your application needs to access the Activity in other packages (for example, select a contact), the packages also need to be specified here. If no package is specified, Monkey allows the system to start the Activity in all the packages. To specify multiple packages, you need to use multiple-p options. Each-p option can only be used for one package.

-C <main-category>
If this parameter is used to specify one or more categories, Monkey allows the system to start only the activities listed by a category in these categories. If no category is specified, Monkey selects the Activity listed in the following categories: Intent. CATEGORY_LAUNCHER or Intent. CATEGORY_MONKEY. To specify multiple categories, you need to use multiple-c options. Each-c option can only be used for one category.

Debugging
-- Dbg-no-events
When this option is set, Monkey will start initially, enter a test Activity, and no further event will be generated. To get the best result, it is combined with-v, one or more packets, and a non-zero value that keeps the Monkey running for 30 seconds or longer, thus providing an environment, monitors the conversion between packages called by applications.

-- Hprof
Set this option to generate a profiling report immediately before and after the Monkey event sequence. This will generate a large file (~ 5 Mb), so use it with caution.

-- Ignore-crashes
In general, Monkey stops running when the application crashes or any runaway exception occurs. If this option is set, Monkey continues to send events to the system until the count is complete.

-- Ignore-timeouts
Generally, when an Application encounters any timeout error (such as the "Application Not Responding" dialog box), the Monkey stops running. If this option is set, Monkey continues to send events to the system until the count is complete.

-- Ignore-security-exceptions
In general, when an application has a license error (such as starting an Activity that requires certain licenses), the Monkey stops running. If this option is set, Monkey continues to send events to the system until the count is complete.

-- Kill-process-after-error
Generally, when a Monkey stops due to an error, the failed application continues to run. When this option is set, the system will be notified to stop the process with an error. Note that the process ends normally (successfully) and does not stop. The device simply remains in the final state after the event ends.

-- Monitor-native-crashes
Monitors and reports crash events of local code in the Android system. If -- kill-process-after-error is set, the system stops running.

-- Wait-dbg
Stop the running Monkey until a debugger is connected to it.

Next, let's look at an instance.

Monkey usage is $ adb shell monkey-p your. package. name-v 500. First, we need to find the package name corresponding to the application in Emulator. At the beginning, I found directories one by one and completed the work in the first seven steps, finally, we found that all application packages are under data/data. You can cd data/data in the shell, and then ls to view all application packages in the current Emulator.

If we want to perform a stress test on APIDemos In the SDK,

1. Create a project in Eclipse

F: \ android-sdk-windows \ platforms \ android-2.0 \ samples \ ApiDemos add to project and click Run. At this time, his APK should be loaded to Emulator.

2. Enter adb shell in the command line

3. Enter ls to view the directory in the current folder. The execution result is as follows:

C: \ Documents ents and Settings \ Administrator> adb shell
# Ls
Ls
Sqlite_stmt_journals
Config
Cache
Sdcard
D
Etc
System
Sys
Sbin
Proc
Init. rc
Init. goldfish. rc
Init
Default. prop
Data
Root
Dev

4. The application packages are all under data. Enter cd data to enter the data folder, as shown below:

# Cd data
Cd data

5. Enter ls to view the content in the folder, as shown below:

# Ls
Ls
Misc
Local
Data
App-private
App
Property
Anr
Backup
Dontpanic
Dalvik-cache
System
Lost + found

6. There is another data. All the applications are under this data. Enter this data and enter the ls as follows:

# Cd data
Cd data
# Ls
Ls
Com. android. mms
Com. android. providers. applications
Com. android. globalsearch
Com. android. calculator2
Com. android. spare_parts
Com. android. gesture. builder
Com. android. music
Com. android. sdksetup
Com. android. packageinstaller
Com. android. fallback
Com. android. providers. settings
Com. android. providers. drm
Com. android. development
Com. android. providers. telephony
Com. android. inputmethod. pinyin
Com.android.html viewer
Com. android. settings
Com. android. netspeed
Com. android. providers. userdictionary
Com. android. browser
Com. android. contacts
Com. android. alarmclock
Com. android. camera
Com. android. providers. contacts
Jp. co. omronsoft. openwnn
Com. android. launcher
Com. android. phone
Com. android. soundrecorder
Com. google. android. providers. enhancedgooglesearch
Com. svox. pico
Com. android. customlocale
Com. android. term
Com. android. providers. downloads
Com. android. providers. media
Com. android. email
Android. tts
Com. android. inputmethod. latin
Com. android. server. vpn
Com. example. android. apis

7. The last one is the application package of APIDemo we just loaded.

8. you can directly enter monkey-p com. example. android. apis-v 50. The result is as follows. You can also exit the shell and enter adb shell monkey-p com. example. android. apis-v 500. During the running process, the applications in the Emulator are constantly switching the screen. You can take a look, haha :)

# Monkey-p com. example. android. apis-v 50
Monkey-p com. example. android. apis-v 50
: Monkey: seed = 0 count = 50
: AllowPackage: com. example. android. apis
: IncludeCategory: android. intent. category. LAUNCHER
: IncludeCategory: android. intent. category. MONKEY
// Event percentages:
// 0: 15.0%
// 1: 10.0%
// 2: 15.0%
// 3: 25.0%
// 4: 15.0%
// 5: 2.0%
// 6: 2.0%
// 7: 1.0%
/// 8: 15.0%
: Switch: # Intent; action = android. intent. action. MAIN; category = android. intent. categ
Ory. LAUNCHER; launchFlags = 0x10000000; component = com. example. android. apis/. ApiDemos
; End
// Allowing start of Intent {act = android. intent. action. MAIN cat = [android. in
Tent. category. LAUNCHER] cmp = com. example. android. apis/. ApiDemos} in package com.
Example. android. apis
: Sending Pointer ACTION_MOVE x =-4.0 y = 2.0
: Sending Pointer ACTION_UP x = 0.0 y = 0.0
// Allowing start of Intent {cmp = com. example. android. apis/. ApiDemos} in pa
Ckage com. example. android. apis
: Sending Pointer ACTION_DOWN x = 207.0 y = 282.0
: Sending Pointer ACTION_UP x = 189.0 y = 289.0
// Allowing start of Intent {cmp = com. example. android. apis/. app. Intents} in
Package com. example. android. apis
: Sending Pointer ACTION_DOWN x = 95.0 y = 259.0
: Sending Pointer ACTION_UP x = 95.0 y = 259.0
: Sending Pointer ACTION_DOWN x = 295.0 y = 223.0
: Sending Pointer ACTION_UP x = 290.0 y = 213.0
: Sending Pointer ACTION_MOVE x =-5.0 y = 3.0
: Dropped: keys = 0 pointers = 0 trackbils = 0 flips = 0
# Network stats: elapsed time = 3799 ms (3799 ms mobile, 0 ms wifi, 0 ms not connecte
D)
// Monkey finished

Related Article

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.