Android Monkey Test

Source: Internet
Author: User

Monkey testing the use of 1--monkey
Original address:
http://www.douban.com/note/257029872/
(Transferred from watercress, copyright belongs to watercress and Douban friends, if offended please forgive and contact us)

Use of Monkey

First, what is Monkey

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.

Ii. Characteristics of Monkey

1, the test object is only the application package, there are certain limitations.

2. The event stream data stream used by the monkey test is random and cannot be customized.

3, can set the Monkeytest object, the number of events, type, frequency, etc.

Three, the basic usage of monkey

The basic syntax is as follows:

$ adb shell monkey [options]

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

$ adb Shell Monkey-pyour.package.name-v 500

Iv. An example of the monkey test

With this example, we can understand the steps of the monkey test and how to know which applications can be tested with monkey.

Under Windows (Note: 2 and 4 are steps to see which application packages we can test, which can be omitted):

1. Launch an Android emulator via eclipse

2. Enter in the command line: ADB devices view device connectivity

C:\Documents ANDSETTINGS\ADMINISTRATOR>ADB Devices

List of devices attached

emulator-5554 Device

3, on the premise of a device connection, enter in the command line: adb shell into the shell interface

C:\Documents andsettings\administrator>adb Shell

#

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

C:\Documents andsettings\administrator>adb Shell

LS Data/data

LS Data/data

Com.google.android.btrouter

Com.android.providers.telephony

Com.android.mms

Com.android.providers.downloads

Com.android.deskclock

Com.android.email

Com.android.providers.media

Com.android.settings

Jp.co.omronsoft.openwnn

Com.android.providers.userdictionary

Com.android.quicksearchbox

Com.android.protips

Com.android.browser

Com.android.launcher

Com.android.term

Com.android.speechrecorder

Com.android.server.vpn

Com.android.defcontainer

Com.svox.pico

Com.android.customlocale

Com.android.development

Com.android.soundrecorder

Com.android.providers.drm

Com.android.spare_parts

Com.android.providers.downloads.ui

Com.android.fallback

Com.android.providers.applications

Com.android.netspeed

Com.android.wallpaper.livepicker

Android.tts

Com.android.htmlviewer

Com.android.music

Com.android.certinstaller

Com.android.inputmethod.pinyin

Com.android.providers.subscribedfeeds

Com.android.inputmethod.latin

Com.android.gallery

Com.android.systemui

Com.android.contacts

Com.android.phone

Com.android.sdksetup

Com.android.calculator2

Com.android.packageinstaller

Com.android.camera

Com.android.providers.settings

Com.thestore.main

Com.android.providers.contacts

5, with Com.android.calculator2 as the object of Monkeytest

#monkey-P COM.ANDROID.CALCULATOR2-V 500

Where-p indicates that the object package –v represents the number of events

During the run, the application in emulator is constantly switching the screen.

According to the different levels of feedback you have selected, you can also see their execution process reports and generated events in monkey.

Note: Specific parameters can be set for reference:

Http://developer.android.com/guide/developing/tools/monkey.html

V. About the stop condition of the monkey test

Monkey test will automatically stop in the following three scenarios during execution:

1. If monkey is qualified to run on one or several specific packages, it will monitor and block attempts to move to other packages.

2. If the application crashes or receives any runaway anomalies, the monkey will stop and error.

3. If the application produces an error that the application does not respond to (Applicationnot responding), Monkey will stop and make a mistake.

It is a stable enough program to pass multiple and different sets of monkey tests.

Monkey Test 2--monkey test strategy
2013-01-08 13:31:44
Testing Strategies for Monkey

I. Classification

The monkey test uses different test scenarios for different objects and for different purposes, first of all, the object, purpose, and type of the test are as follows:

The types of tests are divided into: application stability testing and stress testing

Test objects are divided into: single apk and APK collection

The objectives of the test are: problem-solving tests (ignoring exception tests) and acceptance tests (tests that do not ignore exceptions)

Two. Application Stability testing:

    1. For a single apk

(1) Do not ignore exceptions

When performing an acceptance test of a single apk, a single apk is used and the command execution does not ignore the exception.

For example:
Monkey-p Com.android.mms--throttle 1000-s 100-v-v-v 15000 >/mnt/sdcard/monkey_test.txt &

(2) Ignore exceptions

When a single apk problem-solving test is performed, a single apk is used and the command to ignore the exception is executed, so that you can discover multiple issues in the application during one execution.

For example:
Monkey-p Com.android.mms--throttle 1000-s 100--ignore-crashes--ignore-timeouts-- Ignore-security-exceptions--ignore-native-carshes--monitor-native-crashes-v-v-v 15000 >/mnt/sdcard/monkey_ Test.txt &

    1. For multiple apk

(1) Do not ignore exceptions

For example:

Monkey--pkg-whitelist-file/data/whitelist.txt--throttle 1000-s 100-v-v-v 15000 >/mnt/sdcard/monkey_test.txt & ;

(2) Ignore exceptions

For example:

Monkey--pkg-whitelist-file/data/whitelist.txt--throttle 1000-s--ignore-crashes-- Ignore-timeouts--ignore-security-exceptions--ignore-native-carshes--monitor-native-crashes-v-v-v 15000 >/mnt/ Sdcard/monkey_test.txt &

Three. Application Stress/Robustness Testing

The application's stress/robustness test, which is primarily to shorten the delay between events and events in the Monkey test, verifies that the program works correctly during a fast incident response. This stress/robustness test is performed primarily against a single apk, and we can set the value of--throttle to 500 or smaller, typically using a 500 millisecond delay event.

In the APK collection test, for the high-frequency apk, the long-used apk will be included in the execution of the middle of the application.

APK category specific:

APK for high frequency use: Phone, Contacts, Message, Settings, File Manager, Gallery, Input Method

Long-time apk such as: Phone, Browser, Music player, Camera, Video player, Email, Chat

Other apk such as: Calendar, Notepad, Calculator, FM Radio, Google Search

Analysis of test results of monkey test 3--monkey
2013-01-08 13:32:18
Monkey Test Results Analysis

I. Preliminary analysis methods:

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: Search for "ANR" in the log

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

Two. Detailed analysis of monkey logs:

The log generated by the monkey will be executed, exported from the phone and opened to view the log, and at the very beginning of log, the seed value, the number of executions, and the package name of the test monkey executed.

First we need to see if there is a ANR or an exception in the monkey test, as described above.

Then we will analyze the specific information in log, as follows:

Look at the first switch in log, primarily to see what monkey is doing with that activity, such as the following log, The execution is com.tencent.smtt.SplashActivity, between the next Swtich, if there is a crash or other exception, you can find the problem in the activity.

: Switch: #Intent; action=android.intent.action.main;category=android.intent.category.launcher;launchflags= 0x10000000;component=com.tencent.smtt/. Splashactivity;end

Allowing start of Intent {Act=android.intent.action.main cat=[android.intent.category.launcher]cmp= com.tencent.smtt/. Splashactivity} in the package COM.TENCENT.SMTT

In the following log, sending Pointer Action_down and sending Pointer action_up represent a single click operation currently performed;

Sleeping for milliseconds This log is a monkey test, the throttle set the interval, each time it appears, represents an event.

Sendkey (Action_down)//keycode_dpad_down represents the current execution of a click-down navigation key operation;

Sending Pointer Action_move represents an operation that currently performs a sliding interface.

: Sending Pointer Action_down x=47.0 y=438.0

: Sending Pointer action_up x=47.0 y=438.0

Sleeping for milliseconds

: Sendkey (Action_down)://keycode_dpad_down

: Sendkey (action_up)://keycode_dpad_down

Sleeping for milliseconds

: Sending Pointer action_move x=-2.0 y=3.0

: Sending Pointer action_move x=4.0 y=-3.0

: Sending Pointer action_move x=-5.0 y=-3.0

: Sending Pointer action_move x=3.0 y=4.0

: Sending Pointer action_move x=-4.0 y=1.0

: Sending Pointer action_move x=-1.0 y=-1.0

: Sending Pointer action_move x=-2.0 y=-4.0

If the Monkey test completes successfully, at the end of the log, the number of times the current execution of the event is printed and the time spent;//Monkey finished represents execution completion. Monkey execution interrupt, at the end of log can also see the current number of executions. Monkey execution completed log is as follows:

Events injected:6000

:D ropped:keys=0 pointers=9 trackballs=0 flips=0

Network stats:elapsed Time=808384ms (0ms Mobile, 808384ms WiFi, 0msnot connected)

Monkey finished

Monkey test all options available on the 4--monkey command line
2013-01-08 13:33:12
Monkey all options available on the command line

Conventional

--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 the activity that was selected or unchecked in the test.

Log levels Level 0

* Example Adbshell monkey-p com.htc.weather–v 100

Describe default values, providing only small amounts of information such as startup hints, test completion, and final results

Log levels Level 1

* Example Adbshell monkey-p com.htc.weather–v-v 100

Description provides a more detailed log, including each event message sent to the activity

Log Levels Level 2

* Example Adbshell monkey-p com.htc.weather–v-v–v 100

Description of the most detailed log, including the selected/unchecked activity information in the test

Event

-S <seed>

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

    • Example:

Monkey Test 1:adb shellmonkey-p com.htc.weather–s 10 100

Monkey Test 2:adb shellmonkey-p com.htc.weather–s 10 100

The effect of the two Tests is the same, because the simulated sequence of user actions (a sequence of operations consisting of each operation in a certain order) is the same. The sequence of operations is randomly generated, but as long as we specify the same seed value, we can guarantee that the random sequence of operations generated by the two Tests is exactly the same, so this sequence of operations is pseudo-random;

--throttle<milliseconds>

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.

    • Example: adb shellmonkey-p com.htc.weather–throttle 3000 100

--pct-touch<percent>

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

    • Example: adb shellmonkey-p com.htc.Weather--pct-touch 10 1000

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

    • Example: adb shellmonkey-p com.htc.Weather--pct-motion 20 1000

--pct-trackball<percent>

Adjusts the percentage of track events (the trajectory event consists of one or more random movements, sometimes accompanied by clicks).

    • Example: adb shellmonkey-p com.htc.Weather--pct-trackball 30 1000

--pct-nav<percent>

Adjusts the percentage of the basic navigation event (the navigation event consists of the up/down/left/right from the direction input device).

    • Example: adb shellmonkey-p com.htc.Weather--pct-nav 40 1000

--pct-majornav<percent>

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)

    • Example: adb shellmonkey-p com.htc.Weather--pct-majornav 50 1000

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

    • Example: adb shellmonkey-p com.htc.Weather--pct-syskeys 60 1000

--pct-appswitch<percent>
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.

    • Example: adb shellmonkey-p com.htc.Weather--pct-appswitch 70 1000

--pct-anyevent<percent>
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. * Example: adb shell monkey-p com.htc.Weather

--pct-anyevent 1001000* Specifies the percentage of multiple types of events:

adb shell Monkey-pcom.htc.weather--pct-anyevent--pct-appswitch 50 1000
Note: The total percentage of each event type cannot exceed 100%;

Constraint restrictions

-p<allowed-package-name>

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 options, and each-p option can be used for only one package.
* Specify a package: adb shell monkey-p com.htc.Weather 100

Description: Com.htc.Weather is the package name, 100 is the event count (i.e. let the monkey program simulate 100 random user events).

    • Specify multiple packages: adb shell monkey-p com.htc.weather–pcom.htc.pdfreader-p com.htc.photo.widgets 100

    • Do not specify package: adb shell Monkey 100

Description: Monkey randomly launches the app and sends 100 random events.

    • To view all the packages in the device, execute the following command in the cmd window:

ADB shell

#cd Data/data

#ls

-c<main-category>

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.

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.
* Example 1:adb shellmonkey-p com.htc.Weather--ignore-crashes 1000
Even if the weather program crashes during the test, Monkey continues to send events until the number of events reaches 1000;
* Example 2:ADB Shell monkey-p Com.htc.Weather 1000
During the test, if the weather program crashes, Monkey will stop running.

--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
Stop monkey in execution until there is a debugger connected to it.

Android Monkey Test

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.