原址:https://developer.android.com/studio/test/monkey.html
帮助:google翻译:https://translate.google.cn/
自己学习
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.
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.
译:
Monkey是一个命令行工具,你可以运行在任何一个模拟实例(模拟器)或者是一个设备上。它向系统发送用户事件的伪随机流,作为你正在开发的应用软件上的压力测试。
Monkey包含了许多选项,但是分为了4个主要的类别:
基础配置选项,比如设置尝试事件的数量;
操作上的限制,比如将测试限制在一个包中;
事件类型以及频率;
调试选项。
当Monkey在运行的时候,就会形成事件并且将它们发送给系统。它也会观察被测系统,并且寻找3个条件,会特别对待:
如果你曾经限制Monkey运行在1个或者多个指定包,它会寻找那些尝试定位到其他任何包的命令然后阻止它们;
如果你的应用程序崩溃或者接收到任何未处理的异常,Monkey就会停止并且报告错误;
如果你的应用程序生成应用程序无响应错误,Monkey就会停止并且报告错误。
根据你所选择的详细等级,你将也能看到有关于Monkey进程和正在生成的事件的报告。
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 your.package.name -v 500
译:
你可以用在你开发机器上的命令行或者是一个脚本启动Monkey。因为Monkey运行在模拟器/设备环境里,因此你一定要用在这个环境里的shell启动它。你可以在每个命令前加入abd shell 操作命令,或者通过输入shell,并且直接输入Monkey命令操作。
基本语法:
$ adb shell monkey [options] <event-count>
如果没有指定选项,Monkey将以安静(没有冗余)的模式启动,并将事件发送到安装在你目标设备上任何或者所有的包里(这个设备上的所有软件)。这是一个更为典型的命令行,将会启动你的应用程序并且发送500个伪随机事件:
$ adb shell monkey -p your.package.name -v 500
Command Options Reference
The table belows lists all options you can include on the Monkey command line.
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> | 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 <milliseconds> | 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 <percent> | Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.) | |
--pct-motion <percent> | 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 <percent> | Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.) | |
--pct-majornav <percent> | 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 <percent> | 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 <percent> | 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 <percent> | 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 <allowed-package-name> | 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 <main-category> | 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命令行中包含的:
Category | Option | Description |
General | --help | 打印一个简单的使用指南 |
-v | 在命令行中每增加一个 -v 就会增加详细级别。Level 0 (默认) 提供了小部分信息,只包括启动通知,测试完成和最终结果。Level 1提供了有关测试的更为详细的信息,比如单个事件发送到活动中。 Level 2 提供了更多的设置信息细节,比如选中或未被选择进行测试的活动。 | |
Events | -s <seed> | 伪随机发生器种子值。如果你运行monkey用同样的种子值,就会生成相同的事件序列。 |
--throttle <milliseconds> | 在事件与事件之间插入固定的延时。你可以使用这个选项减慢Monkey速度。如果没有指定时间,将没有延时,并且事件会尽可能快地生成。 | |
--pct-touch <percent> | 调整触屏事件的百分比。(触屏事件是在屏幕上单个位置的下降事件。) | |
--pct-motion <percent> | 调整手势事件的百分比。(手势事件由在屏幕上的某个位置的向下,一系列的伪随机移动和向上事件组成。) | |
--pct-trackball | 调整轨迹球事件的百分比。(轨迹球事件由1个或者更多随机移动,有时候伴随点击。) | |
--pct-nav <percent> | 调整 “基础” 导航事件的百分比。(导航事件由 上/下/左/右,作为来自定向输入设备的输入。) | |
--pct-majornav <percent> | 调整 “主要” 导航事件的百分比。(导航事件通常导致用户界面中的操作,比如中间按钮,返回键,或者是菜单键。) | |
--pct-syskeys <percent> | 调整 “系统” 键事件的百分比。(这些按键通常为系统预留的,比如Home,back,Start Call,End Call,or Volume controls。) | |
--pct-appswitch <percent> | 调整活动启动的百分比。随机间隔,Monkey将会发出一个startctivity()调用,以最大限度地提高包中所有活动的覆盖范围。 | |
--pct-anyevent <percent> | 调整其他类型的事件的百分比。对于所有其他类型的事件,例如按键按钮,设备上其他使用较少的按钮等等,这是一个全面的方法。 | |
Constraints | -p <allowed-package-name> | 如果你用这种方式指定一个或多个包,Monkey只允许系统去访问在这些包下的Activitys。如果你的应用程序访问其他包下的activities(选择一个联系),你也的指定这些包。如果你没有指定任何包,Monkey将会允许系统去启动所有包下的所有activities。指定多个包,多次使用 -p 选项,一个 -p 指定一个包。 |
-c <main-category> | 如果你用这种方式指定一个或多个类别。Monkye只允许系统访问使用指定类别之一列出的所有activities。如果你没有指定任何类别,Monkey会选择列出的类别为Intent。CATEGORY_LAUNCHER 或者 Intent.CATEGORY_MONKEY。要指定多个类别,多次使用 -c选项,一个 -c 指定一个 类别。 | |
Debugging | --dbg-no-events | 指定时,Monkey将执行初始启动到测试活动中,但不会发生任何其他事件。为了获得最佳效果,结合使用 -v,一个或多个包装约束和一个非零节流阀,以保持Monkey运行30秒或更长时间。提供了一个可以监视应用程序调用的程序包转换的环境。 |
--hprof | r如果这个设置了,该选项将在Monkey事件序列之前和之后立即生成分析报告。这将在data/misc中生成大量(5MB)文件,因此请谨慎使用。有关跟踪文件的更多信息,请参阅Traceview。 | |
--ignore-crashes | 通常,Monkey在应用程序遇到崩溃或者遇到了任何类型的没有处理的异常,就会停止。但是如果你指定了这个选项,Monkey会继续给系统发送事件,直到计数达到。 | |
--ignore-timeouts | 通常,Monkey在应用程序遇到任何类型的时间超时错误比如 出现“Application Not Responding”的对话的时候就会停止。但是如果指定了这个选项。Monkey会继续给系统发送事件,直到计数达到。 | |
--ignore-security-exceptions | 通常,Monkey在应用程序遇到任何类型的权限错误,就会停止,比如如果尝试启动需要某些权限的activity。但是如果指定了这个选项。Monkey会继续给系统发送事件,直到计数达到。 | |
--kill-process-after-error | 通常,Monkey会由于错误而停止时,失败的应用程序将保持运行。当这个选项被设置时,它会通知系统停止发生错误的过程。注意,在正常(成功)完成的情况下,启动的进程不会停止,并且设备仅在最后一个事件之后留在最后一个状态。 | |
--monitor-native-crashes | 观看并报告在android系统本机代码中发生的崩溃。如果 --kill-process-after-error 被设置,系统将会停止。 | |
--wait-dbg | Monkey执行停止操作直到被调试器附加到它。 |
举例:
adb shell monkey -p xxx.xxx.xxx -s 100 --throttle 1000 --pct-touch 100 500
没有讲究数据类型,如包名,不需要讲究 “”,直接值输入就好,百分号,毫秒什么都不用加