Use Monkey to test Android system applications

Foreword:

Monkey is a system tool provided by Android.
It sends pseudo-random user event streams (such as key input, touch screen input, gesture input, etc.) to the system to achieve stress testing of the application under development.
Monkey test is a fast and effective method for testing the stability and robustness of software.

The Monkeyrunner tool is not related to the monkey tool; the monkey tool runs directly on the device or simulated adbshell to generate a pseudo-random event stream for the user or the system, while the monkeyrunner tool controls the device through specific commands and events defined by the API on the workbench Or simulator

Test steps:

  • Connect the Android phone to the computer via USB, and check whether the device information is obtained from the command line adb devices
    (adb: Android debug bridge debug bridge, you can directly operate and manage the Android emulator or real machine, function: run the device shell (command line))
    Insert picture description here

  • adb shell pm list packages View all application package names, find the application package name of the APP you want to test, take Sina Weibo as an example
    Insert picture description here

  • Operate for the Sina Weibo APP to be tested and send a pressure test command to Sina Weibo, adb shell monkey -p com.sina.weibo 1000
    Insert picture description here

  • adb shell monkey -v -p com.sina.weibo --pct-touch 100 1000 send 1000 commands, touch events account for 100%, and print
    Insert picture description here


Monkey simulates the user's normal operations through 11 major events : touch events, –pct-touch PERCENT
gesture events, –pct-motion
two - finger zoom events, track events, --pct-trackball
screen rotation events, basic navigation events, –pct -nav
navigation events, -pct-majornav
system key events, start activity events, -pct-appswitch
keyboard events,
other types of events

The Monkeyrunner tool is not related to the
monkey tool ; the monkey tool runs directly in the device or simulated adbshell to generate a pseudo-random event stream for the user or the system, while the monkeyrunner tool controls the device through specific commands and events defined by the API on the workbench Or simulator; monkeyrunner includes three modules: monkeyrunner, monkeydevice, monkeyImage;

adb shell dumpsys window windows | findstr “Current” View APP current activity
adb shell dumpsys activity Running program
dumpsys meminfo Package name View memory usage
adb install path / package.apk Android application

Detailed adb commands can be queried by adb -h

Note that 5037 is the default port of adb . If it is occupied, you cannot continue to execute the adb command;

The Windows system configures the adb server port method itself: It is very simple, as long as the value of ANDROID_ADB_SERVER_PORT is defined in the system environment variable.

Under linux, just export $ ANDROID_ADB_SERVER_PORT = custom port.

It is best to choose a 5-digit port number (10000 ~ 65535), not easy to repeat

Published 22 original articles · praised 5 · visits 4323

Guess you like

Origin blog.csdn.net/weixin_42231208/article/details/89177885