Android monkey test

Source: Internet
Author: User

Android monkey test
Monkey testing is a means of Android automated testing. The monkey test itself is very simple. It simulates users' key input, touch screen input, and gesture input to see how long the device will experience an exception.
When a monkey program is running on a simulator or device, if the user starts a system-level event, such as a click, touch, gesture, or system-level event, it generates a random pulse, therefore, you can use Monkey to load and test your software with random repetition.
The simplest method is to use the following command to use Monkey. This command will start your software and trigger 500 events.
$ ADB shell monkey-v-p your. Package. Name 500
For more information about the monkey command, you can view the UI/Application
Exerciser monkey documentation page.
Com. Android. STK
Com.android.html Viewer
Com. Android. globalsearch
Com. Android. gpstest
Com. Android. googlesearch
WNC. w88.engineermode
Com. Android. calculator2
Com. Android. inputmethod. Latin
Com. svox. Pico
Com. Android. soundrecorder
Com. Android. packageinstaller
Android. TTS
Com. Android. spare_parts
Com. Android. globaltime
Com. Android. sdksetup
Com. quicinc. Bluetooth
Com. Android. Email
Com. Qualcomm. QX. neocore
Com. Android. Development
Com. Android. Term
Com. Android. server. VPN
Com. Android. Contacts
Com. Android. Camera
WNC. w88.factorymode
Com. Android. providers. applicati
Com. Android. providers. Settings
Com. Android. voicedialer
Com. Android. Phone
Com. Android. providers. Contacts
Com. Android. Launcher
Com. Android. MMS
Com. Android. providers. Telephony
Com. Android. providers. userdicti
Com. Android. providers. Media
Com. Android. providers. Calendar
Com. Android. Calendar
Com. Android. providers. DRM
Com. Android. providers. downloads
Com. Android. alarmclock
Com. Android. Settings
Com. Android. Qualcomm
Com. Android. Browser
Com. Android. Music
Monkey is a command line tool that can run in a simulator or a real device. It sends a pseudo-random user event stream to the system to perform stress testing on developing applications. Monkey includes many options, which are roughly divided into four categories:
? Basic configuration options, such as setting the number of attempted events.
? Run constraint options, such as setting to test only one package.
? Event type and frequency.
? Debugging options.
When monkey is running, it generates events and sends them to the system. At the same time, monkey also monitors the system in the test and handles the following three situations:
? If the monkey is limited to one or more specific packages, it will monitor the operations that attempt to switch to other packages and block them.
? If the application crashes or receives any exceptions that are out of control, the monkey stops and reports an error.
? If the application generates an application not responding error, the monkey will stop and report an error.
Based on the selected feedback information of different levels, you can also see the execution process report and generated events in the monkey.
Monkey basic usage:
You can start monkey through the command line or script on the development machine. Since monkey runs in the simulator/device environment, you must use the shell in the environment to start it. You can add the ADB shell before each command to achieve the goal, or enter the monkey command directly after entering the shell. The basic syntax is as follows:
$ ADB shell monkey [Options]
If no options is specified, monkey starts in non-feedback mode and sends any event to all packages installed in the target environment. The following is a more typical command line example. It starts a specified application and sends 500 pseudo-random events to it:
$ ADB shell monkey-p your. Package. Name-V 500
Command Option reference:
The following table lists all the options available for the monkey command line.
Category
Option
Description

General
-- Help
List simple usage.

-V
Each-V in the command line will increase the level of feedback information. Level 0 (default) provides less information except the startup prompt, test completion, and final result. Level 1 provides detailed test information, such as events sent to the activity one by one. Level 2 provides more detailed settings, such as the selected or unselected activity in the test.

Event

-S <seed>
The seed value of the pseudo-random number generator. If you run the monkey again with the same seed value, it generates the same event sequence.

-- Throttle <milliseconds>
Insert a fixed delay between events. This option can reduce the execution speed of monkey. If this option is not specified, the monkey will not be delayed and the event will be generated as quickly as possible.
-- PCT-touch <percent>
Adjust the percentage of touch events (a touch event is a down-up event that occurs at a single location on the screen ).
-- PCT-motion <percent>
Adjust the percentage of Action events (Action events are composed of a down event, a series of pseudo-random events, and an up event somewhere on the screen ).
-- PCT-trackball <percent>
Adjust the percentage of track events (track events consist of one or more random moves, sometimes with clicks ).
-- PCT-nav <percent>
Adjust the percentage of "Basic" navigation events (a navigation event consists of up/down/left/right from the input device ).
-- PCT-majornav <percent>
Adjust the percentage of "Main" navigation events (these events usually lead to operations in the graphic interface, such as the intermediate buttons of the 5-way keyboard, the back button, and the menu button)
-- PCT-syskeys <percent>
Adjust the percentage of system key events (these keys are usually retained and used by the system, such as home, back, start call, end call, and volume control keys ).
-- PCT-Modify witch <percent>
Adjust the percentage of started activity. During the random interval, monkey will execute a startactivity () call as a method to overwrite all the activities in the package to the maximum extent.
-- PCT-anyevent <percent>
Adjust the percentage of other types of events. It includes all other types of events, such as buttons, other infrequently used device buttons, and so on.

Constraints
-P <allowed-package-Name>
If you use this parameter to specify one or more packages, Monkey only allows the system to start the activity in these packages. If your application needs to access the activity in other packages (for example, select a contact), the packages also need to be specified here. If no package is specified, monkey allows the system to start the activity in all the packages. To specify multiple packages, you need to use multiple-P options. Each-P option can only be used for one package.
-C <main-Category>
If this parameter is used to specify one or more categories, monkey allows the system to start only the activities listed by a category in these categories. If no category is specified, monkey selects the activity listed in the following categories: intent. category_launcher or intent. category_monkey. To specify multiple categories, you need to use multiple-C options. Each-C option can only be used for one category.
Debugging
-- Dbg-no-Events
When this option is set, monkey will start initially, enter a test activity, and no further event will be generated. In order to get the best result, it is combined with-V, one or more package constraints, and a non-zero value that keeps the monkey running for 30 seconds or longer to provide an environment, monitors the conversion between packages called by applications.
-- Hprof
Set this option to generate a profiling report immediately before and after the monkey event sequence. This will generate a large file (~ 5 MB), so use it with caution.
-- Ignore-crashes
In general, monkey stops running when the application crashes or any runaway exception occurs. If this option is set, monkey continues to send events to the system until the count is complete.
-- Ignore-timeouts
Generally, when an application encounters any timeout error (such as the "Application not responding" dialog box), the monkey stops running. If this option is set, monkey continues to send events to the system until the count is complete.
-- Ignore-security-Exceptions
In general, when an application has a license error (such as starting an activity that requires certain licenses), the monkey stops running. If this option is set, monkey continues to send events to the system until the count is complete.
-- Kill-process-after-Error
Generally, when a monkey stops due to an error, the failed application continues to run. When this option is set, the system will be notified to stop the process with an error. Note that the process ends normally (successfully) and does not stop. The device simply remains in the final state after the event ends.
-- Monitor-native-crashes
Monitors and reports crash events of local code in the Android system. If -- kill-process-after-error is set, the system stops running.
-- Wait-dbg
Stop the running monkey until a debugger is connected to it.
Monkey [-P allowed_package [-P allowed_package]...]
[-C main_category [-C main_category]...]
[-- Ignore-Crashes] [-- ignore-timeouts]
[-- Ignore-security-exceptions] [-- Monitor-native-crashes]
[-- Kill-process-after-Error] [-- hprof]
[-- PCT-touch percent] [-- PCT-motion percent]
[-- PCT-trackball percent] [-- PCT-syskeys percent]
[-- PCT-nav percent] [-- PCT-majornav percent]
[-- PCT-Reset witch percent] [-- PCT-flip percent]
[-- PCT-anyevent percent]
[-- Wait-dbg] [-- dbg-no-events] [-F scriptfile]
[-- Port port]
[-S seed] [-V [-v]...] [-- throttle millisec]
Count
It seems boring and hard to understand. Even after reading the options, I don't know how to use them.
First, we should understand that we cannot use Monkey to develop the same test and repeat it many times, because monkey is pseudo-random, that is, although there are certain rules to follow, however, we can not specify an action, but we can add command options to limit the operation to a certain range.
Monkey-v-P com. Android. Camera -- throttle 5000 -- PCT-anyevent 100 500
This command is interpreted as follows:
-V: displays the default degree;
-P com. android. camera is a program specified for testing. // allowing start of intent {act = android. intent. action. main cat = [android. intent. category. launcher] CMP = com. android. camera /. camera} in package COM. android. camera: this is the content of the camera that started the test;
-- Throttle 5000 sets the latency;
-- PCT-anyevent 100 sets the percentage of started activity to 100%. If this parameter is not specified, we can see the following percentage of 8 events (described in the preceding options) at the execution start:
# Monkey-v-P com. Android. Camera -- throttle 5000 500
Monkey-v-P com. Android. Camera -- throttle 5000 500
: Monkey: seed = 0 count = 500
: Allowpackage: COM. Android. Camera
: Includecategory: Android. Intent. Category. Launcher
: Includecategory: Android. Intent. Category. Monkey
// Event percentages:
// 0: 15.0%
// 1: 10.0%
// 2: 15.0%
// 3: 25.0%
// 4: 15.0%
// 5: 2.0%
// 6: 2.0%
// 7: 1.0%
/// 8: 15.0%
After an event is specified
# Monkey-v-P com. Android. Camera -- throttle 5000 -- PCT-anyevent 100 500
Monkey-v-P com. Android. Camera -- throttle 5000 -- PCT-anyevent 100 500
: Monkey: seed = 0 count = 500
: Allowpackage: COM. Android. Camera
: Includecategory: Android. Intent. Category. Launcher
: Includecategory: Android. Intent. Category. Monkey
// Event percentages:
// 0: 0.0%
// 1: 0.0%
// 2: 0.0%
// 3: 0.0%
// 4: 0.0%
// 5: 0.0%
// 6: 0.0%
// 7: 0.0%
/// 8: 100.0%
Finally, count indicates that the number of events is set to 500.

Next, let's look at an instance.
Monkey usage is $ ADB shell monkey-p your. package. name-V 500. First, we need to find the package name corresponding to the application in emulator. At the beginning, I found directories one by one and completed the work in the first seven steps, finally, we found that all application packages are under data/data. You can CD Data/data in the shell, and then ls to view all application packages in the current emulator.
If we want to perform a stress test on apidemos In the SDK,
1. create a project in eclipse and add/Android-SDK-Windows/platforms/Android-2.0/samples/apidemos to the project and click Run, the APK should be loaded to the emulator.
2. Enter ADB shell in the command line
3. Enter ls to view the directory in the current folder. The execution result is as follows:
C:/Documents and Settings/Administrator> ADB Shell
# Ls
Ls
Sqlite_stmt_journals
Config
Cache
Sdcard
D
Etc
System
Sys
Sbin
Proc
Init. RC
Init. Goldfish. RC
Init
Default. Prop
Data
Root
Dev
4. The application packages are all under data. Enter CD data to enter the data folder, as shown below:
# CD Data
CD Data
5. Enter ls to view the content in the folder, as shown below:
# Ls
Ls
Misc
Local
Data
App-Private
App
Property
ANR
Backup
Dontpanic
Dalvik-Cache
System
Lost + found
6. There is another data. All the applications are under this data. Enter this data and enter the LS as follows:
# CD Data
CD Data
# Ls
Ls
Com. Android. MMS
Com. Android. providers. Applications
Com. Android. globalsearch
Com. Android. calculator2
Com. Android. spare_parts
Com. Android. gesture. Builder
Com. Android. Music
Com. Android. sdksetup
Com. Android. packageinstaller
Com. Android. Fallback
Com. Android. providers. Settings
Com. Android. providers. DRM
Com. Android. Development
Com. Android. providers. Telephony
Com. Android. inputmethod. Pinyin
Com.android.html Viewer
Com. Android. Settings
Com. Android. netspeed
Com. Android. providers. userdictionary
Com. Android. Browser
Com. Android. Contacts
Com. Android. alarmclock
Com. Android. Camera
Com. Android. providers. Contacts
JP. co. omronsoft. openwnn
Com. Android. Launcher
Com. Android. Phone
Com. Android. soundrecorder
Com. Google. Android. providers. enhancedgooglesearch
Com. svox. Pico
Com. Android. customlocale
Com. Android. Term
Com. Android. providers. downloads
Com. Android. providers. Media
Com. Android. Email
Android. TTS
Com. Android. inputmethod. Latin
Com. Android. server. VPN
Com. example. Android. APIs
7. The last one is the application package of apidemo we just loaded.
8. you can directly enter monkey-p com. example. android. APIS-V 50. The result is as follows. You can also exit the shell and enter ADB shell monkey-p com. example. android. APIS-V 500. During the running process, the applications in the emulator are constantly switching the screen. You can take a look, haha :)
# Monkey-P com. example. Android. APIs-V 50
Monkey-P com. example. Android. APIs-V 50
: Monkey: seed = 0 count = 50
: Allowpackage: COM. example. Android. APIs
: Includecategory: Android. Intent. Category. Launcher
: Includecategory: Android. Intent. Category. Monkey
// Event percentages:
// 0: 15.0%
// 1: 10.0%
// 2: 15.0%
// 3: 25.0%
// 4: 15.0%
// 5: 2.0%
// 6: 2.0%
// 7: 1.0%
/// 8: 15.0%
: Switch: # intent; Action = Android. Intent. Action. Main; Category = Android. Intent. Categ
Ory. launcher; launchflags = 0x10000000; Component = com. example. Android. APIs/. apidemos
; End
// Allowing start of intent {act = android. intent. action. main cat = [android. intent. category. launcher] CMP = com. example. android. APIS /. apidemos} in package COM.
Example. Android. APIs
: Sending pointer action_move x =-4.0 y = 2.0
: Sending pointer action_up x = 0.0 y = 0.0
// Allowing start of intent {CMP = com. example. Android. APIs/. apidemos} in PA
Ckage com. example. Android. APIs
: Sending pointer action_down x = 207.0 y = 282.0
: Sending pointer action_up x = 189.0 y = 289.0
// Allowing start of intent {CMP = com. example. Android. APIs/. App. intents} in
Package com. example. Android. APIs
: Sending pointer action_down x = 95.0 y = 259.0
: Sending pointer action_up x = 95.0 y = 259.0
: Sending pointer action_down x = 295.0 y = 223.0
: Sending pointer action_up x = 290.0 y = 213.0
: Sending pointer action_move x =-5.0 y = 3.0
: Dropped: Keys = 0 pointers = 0 trackbils = 0 flips = 0
# Network stats: elapsed time = 3799 ms (3799 Ms mobile, 0 Ms WiFi, 0 Ms not connecte
D)
// Monkey finished

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.