Monkey测试

http://www.jianshu.com/p/cecaf1728221
http://www.2cto.com/kf/201605/504407.html

UI/Application Exerciser Monkey(UI /应用程序训练器Monkey)

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Monkey是您的运行程序 模拟器或设备,并生成用户事件的伪随机流,例如点击,触摸,或手势,以及若干系统级事件。您可以使用Monkey,你正在开发压力测试的应用程序,以随机但可重复的方式。

Overview 概观

The Monkey is a command-line tool 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.
Monkey是一个命令行工具,你可以在任何模拟器实例或设备上运行。它发送用户事件的伪随机流进入系统,其充当关于你正在开发的应用软件的应力测试。

The Monkey includes a number of options, but they break down into four primary categories:
Monkey包括许多选择,但它们分解为四个主要的类别:

  • 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:
当Monkey运行时,它生成事件并将其发送到系统。它还监视 被测系统,并查找三个条件,其中特别对待:

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.
如果已经限制了Monkey中的一个或多个特定软件包运行,它手表尝试导航到任何其他包,并阻止它们。
如果你的应用程序崩溃或收到任何形式的未处理的异常,Monkey将停止运行并报告错误。
如果你的应用程序生成一个没有响应的应用程序错误,Monkey将停止运行并报告错误。

Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.
根据您所选择的详细程度,你也将看到Monkey的进度报告和正在生成的事件。

Basic Use of the Monkey(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.
您可以使用您的开发机或从脚本命令行启动Monkey。因为Monkey在模拟器/设备环境下运行,必须从在环境中的shell启动。你可以加上前缀做到这一点adb shell每一个命令,或通过输入外壳和直接进入猴命令。

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:
如果不指定任何选项,Monkey将在一个安静的(非冗余)模式下启动,并会发送事件的任何(所有)安装在你的目标包。这里是一个更典型的命令行,这将启动应用程序,并送500的伪随机事件吧:

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

Command Options Reference

The table below lists all options you can include on the Monkey command line.
下表列出了所有选项,你可以包括Monkey命令行上。

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.

Monkey测试主要的命令行如下:

adb shell monkey -p cn.doolii.useng -v -v 10000 >F:\log.txt

此行代码的意思是,-p 指定测试某个应用程序的包名 如cn.doolii.useng,-v 只显示测试出的log等级,-v -v -v为最高级别,打出的log最为详细。-v 10000 是指自动测试10000次,>F:\log.txt 是指将log以文本的格式输出,即存在F盘下。可以打开。

你可能感兴趣的:(android)