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

How to get started with Monkey in APP pressure Stability Test

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

How to get started with APP in Monkey pressure stability test. Aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Brief introduction of Monkey testing

For automated testing on android phones, monkey is much easier to use than cts,Android UnitTest. It actually inherits a section of shell instructions from adb shell.

Related principles of monkey testing

The principle of monkey testing is to use socket communication to simulate the user's keystroke input, touch screen input, gesture input, etc., to see how long the device will be abnormal. When the Monkey program is running in the simulator or device, if the user starts a click, touch, gesture or some system-level event, it will generate random pulses, so you can use Monkey to load and test your software with random repetition.

General steps for using Monkey

1. First confirm that the device (simulator or real machine) is connected successfully. Command: adb devices. The device number indicates that the connection is successful.

two。 Determine the package name of the application to be tested. The reference is as follows

1) Open the CMD command line

2) adb shell enters the shell interface and looks up the package name according to the keywords by viewing the package under data/data.

3. Execute monkey test commands

Adb shell monkey-p your.package.name-- pct-touch 30-- ignore-crashes-- ignore-timeouts--throttle 250-s 2-v-v-v 5000000

Common commands for Monkey

1: common option

-- help: print help

-v: specifies the level of detail of the print information, one-v increases one level, and the default level is 0. -v-v-v is the most detailed log.

2: event option

-s: specifies that random event seed values are generated, and the same seed values produce the same event sequence. Such as:-s 200

-- throttle: the interval after the end of each event-- reduces the pressure on the system (if not specified, the system will send a sequence of events as soon as possible). For example:-- throttle 100

-- pct-touch: specifies the percentage of touch events, such as-- pct-touch 5%, also related to the following option:

-- pct-motion (sliding event)

-pct-trackball (trackball event)

-- pct-nav (navigation event up/down/left/right)

-- pct-majornav (main navigation events back key, menu key)

-- pct-syskeys (system key events Home, Back, startCall, endCall, volumeControl)

-- pct-appswitch (switching between activity)

-- pct-anyevent (any event)

3: constraint option

-p: specify a valid package (if not specified, it is valid for all package in the system). A-p corresponds to a valid package, such as-p com.ckt-p com.ckt.asura

-c:activity must contain at least one specified category before it can be started, otherwise it cannot be started

4: debugging option

-- dbg-no-events: initializes the started activity, but does not generate any events.

-- hprof: after specifying this item, an analysis report is generated immediately before and after the event sequence is sent-- it is generally recommended that you specify this item.

-- ignore-crashes: ignore crashes

-- ignore-timeouts: ignore timeout

-- ignore-security-exceptions: ignore security exceptions

-- kill-process-after-error: kill the process directly after an error occurs

-- monitor-native-crashes: tracks the crash of local methods

-- wait-dbg: do not perform the monkey test until the debugger is connected.

Monkey actual combat

1. Build the monkey test environment:

Install adb before running (the MONKEY test uses the ADB command, so you only need to configure the ADB environment. )

Download the adb command package on 1.pc, decompress it and put it in the C disk directory (that is, install jdk,sdk,jdk, decompress sdk, and configure the environment variable, path plus the directory path of platform-tools and tools)

two。 The phone is connected to the computer through usb, and the usb driver is installed automatically. The connection is successful.

3. Verify that the adb command can run

On the pc side, enter the cmd command line-enter the C:\ tmg directory-- run adb shell. The $symbol indicates that the adb command runs successfully and enters shell mode.

Second, mobile phone settings

The phone screen timeout is set to never turn off to prevent the phone from entering the locked screen state.

Take the htc phone as an example: enter Settings-display-screen standby-set to never turn off.

3. Run monkey

There are three modes of operation: A.PC adb shell monkey+ parameters b PC input adb shell into the phone's Android device and then monkey+ parameter C install a simulator on the mobile phone device to execute monkey+ parameters (mobile phone simulator can search android terminal through Baidu search or 360mobile assistant, install it, you can enter the mokey + parameter in the command line of the simulator)

Here is the first method:

1. Check the package name: check the package name of the apk file in a location on the computer: PC open CMD- to enter the TMG directory-run the device-view the package name aapt dump badging * .apk (the path to the apk file, you can drag and drop directly).

Or directly check the apk package that exists in the phone, enter the adb shell command-phone's data/data folder-- ls to check all the package names and find the package name to test apk.

two。 Run monkey to get 300 random clicks on this package.

Or run monkey to export the log to a location on your computer after 300 random clicks on the package

Adb shell-p package name-v clicks > a location on the computer

3. After the test is stopped, check the exported monkey log and find the problem.

At the beginning of the log, the value of the Monkey execution, the number of times it was executed, and the package name of the test are displayed.

First of all, we need to see if there is an ANR or exception in the Monkey test, a non-response problem (ANR problem): search the log for "ANR" (with a space here), crash problem: search the log for "Exception" to quickly locate key event information. Then look at some of the event actions before the error in Monkey, and execute the action manually to find out the reproduction steps for development.

Fourth, add a little knowledge:

1. How do I install apk?

Adb install xxx.apk-in order to get the address of the installation package for apk, you can drag apk directly to the window of cmd to get it. Returning success indicates that the installation is successful!

two。 How to upload local files to the mobile phone?

Adb push

For example, upload the local whitelist to the mobile end, adb push F:\ whitelist.txt data/local/tmp

3. How to save the log to the PC?

Adb shell monkey-v-v-v 1000 > local address

Example: adb shell monkey-v-v-v 1000 > d:\ monkey.txt

4. Log view supplement

-> output the log to the local first

-> pay attention to the content after switch. General errors will be displayed after this.

-> ANR question: search the ANR keyword in the log

-> run problem: search for Exception problems in the log

This is the answer to the practical question on how to get started with Monkey in the APP pressure stability test. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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: 257

*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

Network Security

Wechat

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

12
Report