This page needs to be cached! Bug Report Hit! Android之monkey测试! - PCYO - 你是谁的,谁是谁,谁为谁憔悴




Monkey是在模拟器上或设备上运行的一个小程序,它能够产生为随机的用户事件流,例如点击(click),触摸(touch),挥手(gestures),还有一系列的系统级事件。你可以使用Monkey来给你正在开发的程序做随机的,但可重复的压力测试 。
The Monkey is a command-line tool that that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.

The Monkey includes a number of options, but they break down into four primary categories:

Basic configuration options, such as setting the number of events to attempt.Operational constraints, such as restricting the test to a single package.Event types and frequencies.Debugging options.

When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially:

If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to any other packages, and blocks them.If your application crashes or receives any sort of unhandled exception, the Monkey will stop and report the error.If your application generates an application not responding error, the Monkey will stop and report the error.

Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.

Basic Use of the Monkey

You can launch the Monkey using a command line on your development machine or from a script. Because the Monkey runs in the emulator/device environment, you must launch it from a shell in that environment. You can do this by prefacing adb shell to each command, or by entering the shell and entering Monkey commands directly.

The basic syntax is:

$ adb shell monkey [options] <event-count>

With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send events to any (and all) packages installed on your target. Here is a more typical command line, which will launch your application and send 500 pseudo-random events to it:

$ adb shell monkey -p -v 500




· 基本配置选项,如设置尝试的事件数量。

· 运行约束选项,如设置只对单独的一个包进行测试。

· 事件类型和频率。

· 调试选项。


· 如果限定了Monkey运行在一个或几个特定的包上,那么它会监测试图转到其它包的操作,并对其进行阻止。

· 如果应用程序崩溃或接收到任何失控异常,Monkey将停止并报错。

· 如果应用程序产生了应用程序不响应(application not responding)的错误,Monkey将会停止并报错。



可以通过开发机器上的命令行或脚本来启动Monkey。由于Monkey运行在模拟器/设备环境中,所以必须用其环境中的shell来进行启动。可以通过在每条命令前加上adb shell来达到目的,也可以进入Shell后直接输入Monkey命令。基本语法如下:

$ adb shell monkey [options]


$ adb shell monkey -p -v 500


本原创文章未经允许不得转载 | 当前页面:PCYO » Android之monkey测试!


This page loaded in 0.001335 seconds