Android App Stress test-monkey

Source: Internet
Author: User
Tags root access

Stress test-monkey Learning Monkey Test features
    1. What is Monkey test? As its name, like a monkey, although nothing to understand, but can be a bit messy, can be understood as stress testing. Do any random action within the specified time or number of times, and the action includes clicking, sliding ...
    2. Monkey Test Objective: To reduce the crash rate by simulating the user's random operating time, exposing the in-app crash
    3. Monkey Test Range expected: In addition to some system settings, we want the range to remain in the application under test, plus some additional interrupt testing
    4. Can only find crash, single-replication and resolution crash still need to rely on the developer
    5. Exposing all crash is less realistic and can only be reduced to a certain extent crash
first, what is Monkey

Monkey is a command-line tool provided by the Android SDK (a command-line automated test tool on the Android platform) that can be run in the emulator or 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 includes many options, which are broadly divided into four categories:

    • Basic configuration options, such as setting the number of events attempted
    • Run constraint options, such as setting test only for a single package
    • Event Type and frequency
    • Debugging options

When the monkey is running, it generates events and sends them to the system. At the same time, the monkey also monitors the system under test and handles the following three special cases (automatic stop):

    • If Monkey is qualified to run on one or several specific packages, it will monitor and block attempts to move to other packages.
    • If the application crashes or receives any runaway exceptions, the monkey will stop and error.
    • If the application produces an error that the application does not respond to (anr:application not responding), Monkey will stop and make a mistake.

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

Second, test preparation

    • Android official website Download Android-sdk-windows package, extract to a directory, without installation, such as D:\android-sdk-windows;
    • Environment variable configuration: Add D:\android-sdk-windows\platform-tools;d:\android-sdk-windows\tools under Path directory (semicolon separated, Make sure that the Platform-tools and tools files are downloaded and that the path is correct)
    • Monkey test must first enter the Android device adb Shell (Android SDK Environment configuration is not described here, there are many online) steps are as follows:

1. Start and run->cmd

2. USB connection phone, enter adb shell command

3. After entering the phone, enter the corresponding monkey command to test

iii. Basic command format for Monkey    

The basic syntax is as follows:

1, $ adb shell monkey [options]

ADB shell monkey–p Package –v test times

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 starts the Com.dianping.XXX package and sends 500 pseudo-random events to it: $ adb shell monkey-p com.dianping.xxx-v 500

2. Perform a single apk:

Monkey–p <options>-C <options>-S <seed> < limit statements >--throttle <milliseconds>-v execution times > c:\m Onkey_test.txt

3. Execute APK Collection:

Monkey–pkg-blacklist-file/data/blacklist.txt-c <options>-S <seed> < restriction statements >--throttle < Milliseconds>-V executions > C:\blacklist_test.txt//Do not blacklist applications

Or

Monkey–pkg-whitelist-file/data/whitelist.txt-c <options>-S <seed> < restriction statements >--throttle < Milliseconds>-V executions > C:\whitelist_test.txt/Whitelist Apps

iv. test Log acquisition

With monkey test, in order to facilitate the analysis of the problem, you can add "|logcat-v time" after the command Monkey command, so that you can test the side of the print log (remember to save the log text with the terminal) for example:

adb shell monkey–p com.dianping.xxx–v 20000|logcat-v Time

But this combination after the monkey test is complete, logcat is still executing, and the test needs to be noted

If the test monkey encounters crash or ANR (the program is forced to quit or not respond), you need to provide traces.txt while fetching the log,

The steps are as follows:{ adb pull/data/anr/traces.txt.}

1. The beta version requires root access

2. Enter the DATA/ANR directory below

3. Copy the Traces.txt file to the TF card and copy it to the software analysis for eg. Trace View

Five, save Monkey log and cell phone log to sdcard

First, enter the ADB shell in CMD or terminal

Second, the implementation of monkey, such as

Monkey-p Com.dianping.XXX--throttle--ignore-crashes--ignore-timeouts--ignore-security-exceptions-- Ignore-native-crashes--monitor-native-crashes-v-v-v >/mnt/sdcard/monkey.txt & logcat-v Time >/mnt/ Sdcard/logcat.txt

Note: If you do not want to generate a Logcat file, remove the red flag (& logcat-v time >/mnt/sdcard/logcat.txt)

Third, the terminal to open the storage log address, such as

Cd/users/wengyb/documents

Four, drag the log to the computer, such as

ADB pull/mnt/sdcard/monkey.txt

Six, manual stop Monkey

ADB shell PS (lookup process PID)

adb shell kill pid (Kill process)

Seven,Monkey Command parameter introduction

Classification

Parameters

Meaning

Note

& nbsp;

 

basic

--help

 

-v

Each of the command line-V will increase the level of feedback information

  • level 0 (default) provides less information in addition to startup prompts, test completion, and final results. eg: adb shell monkey -p com.dianping.xxx–v 100
  • level 1 provides more detailed testing information, such as events sent individually to the activity. Eg: adb shell monkey -p com.dianping.xxx–v-v
  • level 2 provides more detailed setup information, such as selected or unchecked activity in the test.  eg: adb shell monkey -p com.dianping.xxx–v–v–v

Event

-S

  • Seed value of the pseudo-random number generator
  • If you run monkey again with the same seed value, it will generate the same sequence of events
  • Monkey test 1:adb Shell monkey-p com.dianping.xxx–s 10 100
  • Monkey test 2:adb Shell monkey-p com.dianping.xxx–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

adb shell monkey -p com.dianping.xxx –throttle  3000 100

Adjustment percentage

-pct+{-Event Name}

--pct-touch

Adjust the percentage of touch events

Touch event is a down-up event that occurs in a single location on the screen

--pct-motion

Adjust 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

--pct-trackball

Adjust the percentage of track events

A trajectory event consists of one or several random movements, sometimes accompanied by a click

--pct-nav

Adjust the percentage of the basic navigation event

Navigation events consist of up/down/left/right from the direction input device

--pct-majornav

Adjust the percentage of the primary navigation event

These navigation events usually trigger actions in the graphical interface, such as: 5-way keyboard, rewind button, menu key

--pct-syskeys

Adjust 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

--pct-appswitch

Adjust the percentage of startup activity

In a random interval, monkey will execute a startactivity () call as a way to maximally cover all activity in the package

--PCT-ANYEVENT&NBSP;

Adjust the percentage of other types of events

 

&NBSP;

constraint restrictions

-P&NBSP;

  • at the same time.

&NBSP;

-C&NBSP;

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

--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 initiating an activity that requires some license), 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 went wrong will continue to be in a running state
  • When this option is set, the system will be notified of the process of stopping the error.

The normal (successful) end, and does not stop the process from starting, the device simply remains in the final state after the end event

--monitor-native-crashes

  • Monitor and report crash events for native code in Android systems
  • 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

Eight,Monkey instance test

Under Mac:

1. Launch an Android emulator via Eclipse or connect to the real machine

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

3, on the premise of a device connection, enter in the command line: adb shell into the shell interface. If there is more than one device, the plus-s parameter specifies: adb-s devicename Shell

4. Find the package name in which we need to test Com.dianping.XXX

5. View the application package under the Data/data folder (the testable application package is under this directory)

LS Data/data

If Opendir Failed,permission denied appears, it can be resolved with root

Type Su root

Then type LS data/data to view the package

6, Com.dianping.XXX as the object of the Monkeytest command line "monkey-p com.dianping.xxx-v , where-p indicates that the object package –v represents the number of events

During the run, the applications in the emulator/real machine are constantly switching screens.

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

ix. Test Cases

Monkey-p Com.dianping.XXX--throttle--ignore-crashes--ignore-timeouts--ignore-security-exceptions-- Ignore-native-crashes--monitor-native-crashes-v-v-v >/mnt/sdcard/monkey.txt

Cd/users/wengyb/documents

ADB pull/mnt/sdcard/monkey.txt

Android App Stress test-monkey

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.