Preface

There’s a Monkey existed in Android OS. Android device would do the things randomly once you launch the Monkey program in Android device.

Typically, we used Monkey to do the stability test against Android device. Although it’s not predictable for running action by Monkey program, we still can limit some actions for Monkey program under particular condition(s). Let’s look how Monkey benefit the quality of Android device.

What does Money stand for?

There’are two kind of Monkey program in Android. However they’re totally different for the purpose. They’re monkeyrunner and Money program. For the former one, Android device can be controlled by pre-defined scenario/action. For the poster one, it generates random events for Android device.

By different purpose, we often used monkeyrunner to do the functional test and used Monkey to do the stability test against Android device.

I’ve a separate page to talk about monkeyrunner. We are going to talk about the Monkey here.

Why do we use monkey to test our product?

It’s hardly to predict each user how to use their Android device. Hence, utilize a good tool to help our work is a important matter. A good qualified product should be not lockup or reboot occurred even the device is operated by arbitrary operations. This is the reason why we used Monkey to help find the quality issue early.

How to use Monkey program?

Monkey is existed in Android devices. When you want to launch Monkey program, you need to use shell command by ADB tool on computer.

 

 

Ex:

adb shell monkey -v 500

The above command  shows you an example that monkey would generate 500 events randomly against Android.

Here are the options you can use for Monkey program and announce on official Android Dev Site.

    Category Option Description

General --help Prints a simple usage guide.
-v Each -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Level 2 provides more detailed setup information such as activities selected or not selected for testing.
Events -s Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events.
--throttle Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible.
--pct-touch Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.)
--pct-motion Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event.)
--pct-trackball Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.)
--pct-nav Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)
--pct-majornav Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.)
--pct-syskeys Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.)
--pct-appswitch Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package.
--pct-anyevent Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.
Constraints -p If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you’ll need to specify those packages as well. If you don’t specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times — one -p option per package.
-c If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don’t specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times — one -c option per category.
Debugging --dbg-no-events When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application.
--hprof If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files.
--ignore-crashes Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-timeouts Normally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-security-exceptions Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--kill-process-after-error Normally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event.
--monitor-native-crashes Watches for and reports crashes occurring in the Android system native code. If –kill-process-after-error is set, the system will stop.
--wait-dbg Stops the Monkey from executing until a debugger is attached to it.

ex:

adb shell "monkey -s 1 –throttle 100 -v -v -v –ignore-crashes –ignore-timeouts –ignore-security-exceptions 99999999"

In this case, we expect to see if any operation would cause the system reboot or lockup and ignore the factors that would cause the Monkey program stopped. Take a look on the description aforementioned for the condition that command used in this example.

There’re two options we cannot see the description on official web site. However they can be found on help description when you send the command adb shell monkey to Android device. Let’s take a look on them below.

Constraints –pkg-blacklist-file Set a blacklist for the package that are not going to do the test by Monkey. This option are followed by a text file. The text file contain a list of packages. Note, each package can only be listed on one line.
–pkg-whitelist-file Set a whitelist for the package that are going to do the test by Monkey. The random event would only be generated by specified package name in whiltelist. This option are followed by a text file. The text file contain a list of packages. Note, each package can only be listed on one line.

Ex:

adb shell "monkey -v — pkg-blacklist-file /data/local/tmp/ blacklist.txt 500"

The content of blacklist.txt is as follows,

com.google.android.apps.maps

com.android.launcher

In this case, Monkey would not do anything for Google Map and Launcher. It’s also a special case because we set Launcher in blacklist. You may only see the lock screen and unknow what the Monkey is doing. You can check logcat log to see if any action that Monkey does. If you remove the com.android.launcher from blacklist.txt, the Monkey would not do the things for Google Map only. 


Reference

UI/Application Exerciser Monkey,  http://developer.android.com/tools/help/monkey.html

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()