`
yuanlanjun
  • 浏览: 1188121 次
文章分类
社区版块
存档分类
最新评论

Android之自动化压力测试工具:Monkey的使用

 
阅读更多

monkey 压力测试
adb -d shell monkey -p your.package.name -v 6000

一、 什么是Monkey

Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中。它向系统发送伪随机的用户事件流(如按键输入、触摸屏输入、手势输入等),实现对正在开发的应用程序进行压力测试。Monkey测试是一种为了测试软件的稳定性、健壮性的快速有效的方法。

二、 Monkey的特征

1、测试的对象仅为应用程序包,有一定的局限性。

2、 Monky测试使用的事件流数据流是随机的,不能进行自定义。

3、可对MonkeyTest的对象,事件数量,类型,频率等进行设置。

三、Monkey的基本用法

基本语法如下:

$ adb shell monkey [options]

如果不指定options,Monkey将以无反馈模式启动,并把事件任意发送到安装在目标环境中的全部包。下面是一个更为典型的命令行示例,它启动指定的应用程序,并向其发送1500个伪随机事件:

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

$ monkey -p(package的意思) 指定文件名 -v(测试的次数和频率) number(次数)

四、Monkey测试的一个实例

通过这个实例,我们能理解Monkey测试的步骤以及如何知道哪些应用程序能够用Monkey进行测试。

Windows下(注:2—4步是为了查看我们可以测试哪些应用程序包,可省略):

1、 通过eclipse启动一个Android的emulator

2、 在命令行中输入:adb devices查看设备连接情况

C:\Documents and Settings\Administrator>adb devices

List of devices attached

emulator-5554 device

3、 在有设备连接的前提下,在命令行中输入:adb shell 进入shell界面

C:\Documents and Settings\Administrator>adb shell

#

4、 查看data/data文件夹下的应用程序包。注:我们能测试的应用程序包都在这个目录下面

C:\Documents and Settings\Administrator>adb shell

# ls data/data

ls data/data

com.google.android.btrouter

com.android.providers.telephony

com.android.mms

com.android.providers.downloads

com.android.deskclock

com.android.email

com.android.providers.media

com.android.settings

jp.co.omronsoft.openwnn

com.android.providers.userdictionary

com.android.quicksearchbox

com.android.protips

com.android.browser

com.android.launcher

com.android.term

com.android.speechrecorder

com.android.server.vpn

com.android.defcontainer

com.svox.pico

com.android.customlocale

com.android.development

com.android.soundrecorder

com.android.providers.drm

com.android.spare_parts

com.android.providers.downloads.ui

com.android.fallback

com.android.providers.applications

com.android.netspeed

com.android.wallpaper.livepicker

android.tts

com.android.htmlviewer

com.android.music

com.android.certinstaller

com.android.inputmethod.pinyin

com.android.providers.subscribedfeeds

com.android.inputmethod.latin

com.android.gallery

com.android.systemui

com.android.contacts

com.android.phone

com.android.sdksetup

com.android.calculator2

com.android.packageinstaller

com.android.camera

com.android.providers.settings

com.thestore.main

com.android.providers.contacts

5、 以com.android.camera作为对象进行MonkeyTest

#monkey -p com.android.camera -v 500

其中-p表示对象包 –v 表示事件数量

运行过程中,Emulator中的应用程序在不断地切换画面。

按照选定的不同级别的反馈信息,在Monkey中还可以看到其执行过程报告和生成的事件。

注:具体参数的设定可参考:

http://developer.android.com/guide/developing/tools/monkey.html

五、关于Monkey测试的停止条件

Monkey Test执行过程中在下列三种情况下会自动停止:

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

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

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

通过多次并且不同设定下的Monkey测试才算它是一个稳定性足够的程序。


下面是开发文档的原文,对其他的命令也有详细解释::
http://developer.android.com/guide/developing/tools/monkey.html:

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



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 <percent>

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.


分享到:
评论

相关推荐

    android自动化测试工具--Monkey介绍

    Android自动化测试工具-Monkey介绍及使用帮助

    几款Android应用自动化测试工具

    简述:本文介绍几款流行的Android应用自动化测试工具。Monkey测试:随机测试,压力测试,运行在模拟器或实际设备中。MonkeyRunner测试:操作简单,可录制测试脚本,可视化操作,主要生成坐标的自动化操作,移植性不...

    Android 自动化测试框架

    Android常用的自动化测试工具框架: Monkey,MonkeyRunner,UIAutomator,Robotium,Appium,Monkey Talk 一、Monkey  是Android SDK自带的测试工具,是一个命令行工具,可以运行在模拟器中或者实际设备中,它向...

    Android自动化压力测试图解教程——Monkey工具

    NULL 博文链接:https://wpf814533631.iteye.com/blog/1709387

    monkey测试工具

    monkey测试工具,用于Android自动化测试,功能测试

    Android自动化测试

    在Android测试中常用的测试包括:Monkey和MonkeyRunner以及robotium,本文中主要介绍下Monkey和MonkeyRunner自动化测试。Monkey是一个命令行工具,可以运行在模拟器里或实际设备中,它是一种轻量级的性能测试工具。...

    Android平台自动测试之Monkey测试工具

    最近开始研究Android自动化测试方法,对其中的一些工具、方法和框架做了一些简单的整理,其中包括android测试框架、CTS、Monkey、Monkeyrunner、benchmark、其它testtool等等。因接触时间很短,很多地方有不足之处,...

    Android自动测试工具Monkey

    最近开始研究Android自动化测试方法,对其中的一些工具、方法和框架做了一些简单的整理,其中包括android测试框架、CTS、Monkey、Monkeyrunner、benchmark、其它test tool等等。因接触时间很短,很多地方有不足之处...

    学习笔记之Android自动化测试工具Monkey

    Monkey测试是Android平台下自动化测试的一种快速有效的手段,通过Monkey工具可以模拟用户触摸屏幕、滑动轨迹球、按键等操作来对模拟器或者手机设备上的软件进行压力测试,检测该软件的稳定性、健壮性。它的原理是向...

    monkey可视化工具

    Monkey是Android SDK自带的自动化测试工具,可以运行在模拟器里或实际设备中,它向系统发送随机的用户事件流,如按键输入、触摸屏输入、手势输入、Sensor 事件等,实现对正在开发的应用程序进行压力测试。...

    Android Monkey压力测试详细介绍

    Monkey会发送伪随机的用户事件流,适合对app做压力测试 阅读目录 环境搭建 什么是Monkey Monkey 用来做什么 Monkey程序介绍 Monkey 架构 Monkey弱点 Monkey 参数大全 Monkey 命令 基本参数介绍 Monkey ...

    App测试之真机自动化测试-教程

    移动互联网开发者和测试人员在Android应用开发或测试过程中,经常需要对App应用程序进行性能测试、压力测试,或者GUI功能测试,以找出程序中隐藏的问题,Android SDK提供了Monkey test工具,Monkey test是一个随机...

    测试工具-itestin

    移动互联网开发者和测试人员在Android应用开发或测试过程中,经常需要对App应用程序进行性能测试、压力测试,或者GUI功能测试,以找出程序中隐藏的问题,Android SDK提供了Monkey test工具,Monkey test是一个随机...

    monkey-命令脚本生成工具

    Monkey是Android SDK自带的自动化测试工具,可以运行在模拟器里或实际设备中,它向系统发送随机的用户事件流,如按键输入、触摸屏输入、手势输入、Sensor 事件等,实现对正在开发的应用程序进行压力测试。...

    [iTest]Android开发者性能测试工具

    同志们在Android应用开发或测试过程中,经常需要对应用程序进行性能或压力测试,或者GUI功能测试,以找出程序中隐藏的问题,iTest能精确测试应用程序的每一个功能,为广大开发人员和测试人员提供了一款简单易用的...

    自动化monkey

    有时候我们需要对一个软件进行压力测试,检查该软件的性能。如果是人工进行测试的话,效率会低很多,而且会比较枯燥。这时,Android中的一个命令行工具Monkey就可以为我们减轻很多重复而又繁琐的工作。

Global site tag (gtag.js) - Google Analytics