Android Automatic test tool Monkey

  • 2020-12-21 18:09:54
  • OfStack

Preface:

Recently, I started to study the Android automated test method, and made a simple arrangement for 1 of the tools, methods and frameworks, including android test framework, CTS, Monkey, Monkeyrunner, benchmark, other test tool and so on. Due to the short contact time, there are many shortcomings, I hope to communicate with you more.

1. Monkey definition

Explore what software testing tools are available, and this article focuses on the Monkey tool. Monkey test is a means of Android platform automation test. The Monkey program simulates the user's touch screen, slide, button and other operations to carry out stress test on the program on the device and detect how long the program will be abnormal. The time interval of each operation is set by our testers through parameters. In general, we set the time interval of each operation to 500ms.

Monkey Program Description:

Monkey program used by system at Android, Java language, stored in Android file system path is: / system framework/monkey jar

Note: The Monkey.jar program is started by an Shell script named "monkey". The shell script in the Android file system has the following path: /system/bin/monkey;

This enables the Monkey test by executing: adb shell monkey {+ command parameter} in the CMD window.

2. Monkey characteristics

1, the test object is only the application package, there is a certain limitation.

2. The event flow data flow used in Monky test is random and cannot be customized.

3. MonkeyTest can be set for objects, number of events, type, frequency, etc.

3. Basic usage of Monkey

The basic syntax is as follows:

$ adb shell monkey [options]

If you do not specify options, Monkey will start in no-feedback mode and send the event arbitrarily to all packages installed in the target environment. Here is a more typical command line example that starts the specified application and sends 500 pseudo-random events to it:

$ adb shell monkey -p your.package.name -v 500

4. An example of Monkey test

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

Under Windows (note: Step 2-4 is to see which application packages we can test, omitted) :

1. Start one emulator via eclipse

2. Enter adb devices on the command line to check the device connection


C:\Documents and Settings\Administrator>adb devices
List of devices attached
emulator-5554 device

3. Enter adb shell into the shell interface by typing adb shell on the command line under the premise of device connection

C:\Documents and Settings\Administrator > adb shell

#

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


C:\Documents and Settings\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. Take MonkeyTest.android.calculator2 as the object for MonkeyTest

#monkey -p com.android.calculator2 -v 500

Where -ES152en represents the object package. v represents the level of feedback information

As it runs, the applications in Emulator are constantly switching screens.

In Monkey, you can also see the events reported and generated during its execution in terms of the different levels of feedback selected.

Note: For the setting of specific parameters, please refer to:

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

5. Stop conditions for Monkey test

Monkey Test will automatically stop during execution under the following three circumstances:

1. If you restrict Monkey to run on one or more specific packets, it will monitor and block attempts to switch to other packets.

2. If the application crashes or receives any out-of-control exceptions, Monkey will stop and report an error.

3. If the application produces an error (application not responding) which the application does not respond to, Monkey will stop and report an error.

It is considered to be a stable enough program after several Monkey tests with different Settings.

So much for Android automatic testing tool Monkey. We will continue to update the knowledge of money testing tool in the future. Please stay tuned.


Related articles: