Android monkey 命令详解

Monkey命令详解 monkey测试命令 monkey命令:adb shell monkey {+命令参数} b)注意: 所有的参数都需要放在monkey和设置的次数之间; 参数的顺序可以调整 若带了-p ,-p必须放在monkey之后,参数必须在-p和次数之间 2.monkey基础命令 adb shell monkey -p 包名 -v -s seed值 压测次数 1.1.参数-p 此命令用于指定要测试的包,若不指定则在整个系统中执行 a)指定一个包执行10次:adb shell monkey -p 包名 阅读详情
AI摘要

本文详细介绍Android平台上的Monkey命令,包括其基本用法、事件类型、调试选项等,并通过具体示例展示了如何利用Monkey命令进行压力测试。

monkey 是一个运行在模拟器或者Android设备中可以产生类似用户点击、触摸、手势以及一些系统级的伪随机事件流的程序。
我们可以通过命令让monkey向模拟器或者Android设备发送伪随机事件流来对我们开发的App进行压力测试。

monkey的基本用法:

adb shell monkey [options] <event-count>
adb shell monkey 为固定语句,<event-count> 这里是指让monkey向系统发送多少次伪随机事件,重点和关键在[options]选项中,这就引出了我们下面要介绍的

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

这个表是google 官网中介绍monkey命令给出的,google 对monkey命令分了四类:

1. 基本配置选项,如设置事件的数量、查看帮助信息等。

2. 操作的约束,如通过包名限制哪些应用可以被测试。

3. 事件的类型和频率,如点击事件占比多少、触摸事件又占多少以及事件之间的间隔时间等。

4. 调试选项,如是否忽略crashes、ANR等。

下面以测试小例子的形式对上面的命令进行详细讲解:

adb shell monkey 或者 adb shell monkey -help

查看help得到的monkey选项命令比google官网中的要多一些,主要是一些更高级的命令,如通过脚本文件进行monkey测试等。

adb shell monkey -p your.package.name 500
作用:-p 为约束命令,作用是约束只对某个应用进行测试,your.package.name是你要进行测试的应用包名,如果要对多个应用进行测试可以使用多个-p

例:adb shell monkey -p com.android.settings 500 对系统设置应用进行monkey测试发送500个随机事件

adb shell monkey -p com.android.settings -p com.android.calculator2 500 对系统设置应用和计算器应用进行monkey测试共发送500个随机事件

注:如果不使用-p约束,如 adb shell monkey 500 那么将会对手机中的所有应用进行随机测试共发送500个随机事件

-v
adb shell monkey -v 500
作用:命令行中的每个-v都将增加测试信息的详细级别

Level 0 (默认)提供了很少的信息除了启动通知,测试完成,和最终结果。-v

Level 1 提供了更详细的测试运行,如个别事件被发送到您的Activity。 -v -v
Level 2 提供了更详细的设置等信息如Activity选中或未选中的测试信息。 -v -v -v

根据您对测试结果要求的详细程度来确定您用几个 -v,一般会用-v -v -v 最详细的输出到指定文件中,方便查找bug的原因。

-s <seed>
adb shell monkey -s 8888 -v -v -v 500
作用:伪随机数生成器的种子值,如果用相同的种子值再次运行monkey,将生成相同的事件序列。(该种子值对于Bug复现至关重要)
注:如果不指定种子值,系统会随机生成一个种子值,在出现Bug时该种子值会和Bug信息一起被输出,这也是为了便于复现该Bug

--throttle <milliseconds>
adb shell monkey --throttle 300 -v 500
作用:在事件之间插入特定的延时时间(单位毫秒),这样做可以延缓monkey执行事件的速度,默认没有延时,monkey会以最快速度将指定的事件个数执行完。
注:建议使用该参数,经验值300,这是模拟人操作的速度

--pct-touch <percent>
adb shell monkey --pct-touch 50 -v -v 500
作用:指定touch(触摸)事件的百分比,touch事件是由一个DOWN和一个UP组成,按下并抬起即是一个touch事件
注:若不指定任何事件的百分比,系统将随机分配各种事件的百分比

--pct-motion <percent>
adb shell monkey --pct-motion 100 -v -v 500
作用:指定motion(手势)事件百分比,motion事件是由屏幕上某处一个down事件、一系列伪随机的移动事件和一个up事件组成

注:移动事件是直线移动

--pct-trackball <percent>
adb shell monkey --pct-trackball 20 -v -v 500
作用:指定trackball(轨迹球)事件的百分比,滚动球事件由一个或多个随机的移动事件组成,有时会伴随着点击事件
注:移动事件可以是曲线移动

下面几个事件与上面的类似,这里集中介绍
--pct-nav <percent>
指定基本的导航事件百分比。导航事件由方向输入设备的上下左右按键所触发的事件组成,即四个方向键
--pct-majornav <percent>
指定主导航事件百分比。这些导航事件通常会导致UI界面发生变化,如5-way键盘的中间键,返回按键、菜单按键
--pct-syskeys <percent>
指定系统事件百分比。这些按键通常由系统保留使用,如Home、Back、Start Call、End Call、音量调节
--pct-appswitch <percent>
指定Activity启动的百分比。在随机的时间间隔中,monkey执行startActivity()方法,最大程度地覆盖应用中全部的Activity
--pct-anyevent <percent>
指定其他事件的百分比。包含所有其他事件,如按键、其他在设备上不常用的按钮等
--ignore-crashes
adb shell monkey --ignore-crashes -v -v 500
作用:忽略crashes,测试过程中发生crashes继续进行测试直到执行完指定的事件数,如果不忽略遇到crashesmonkey测试会停止

--ignore-timeouts
adb shell monkey --ignore-timeouts -v -v 500
作用:忽略ANR,测试过程中发生ANR继续进行直到执行完指定的事件数,如果不忽略遇到ANR测试也会终止

结合上面的介绍下面写一个比较全面的monkey测试命令

adb shell monkey -v -v -v -s 8888 --throttle 300 --pct-touch 30 --pct-motion 25 --pct-appswitch 25 --pct-majornav 5 --pct-nav 0 --pct-trackball 0 -p com.wwdy.app 10000 >D:\monkey.txt
这是一个比较完整的monkey测试命令,3个-v显示最详细的测试信息,指定种子值为8888,指定触摸事件占30%、手势事件占25%、Activity跳转占25%、主导航占5%、方向导航0%、轨迹球0%,剩下的15%随机分配给其它未指定的事件,约束只测试包名为com.wwdy.app的应用,指定事件数为10000次,输出的测试信息保存到D盘的monkey.txt文件中。
由于10000次耗时太长,这里改成10次执行该命令向大家解释一下测试结果信息。(正式测试可改成10000甚至更多次)


其实我们重点关注的还是有没有Bug,一般来说如果Event injected 个数与我们指定测试的事件数相同则没有遇到Bug(前提没有设置--ignore -crashes和--ignore -timeouts),在最后结束时可以看到// Monkey finished。


ADB常用命令及Monkey测试 一、Monkey测试Monkey测试是一种为了测试软件的稳定性、健壮性的快速有效的方法Monkey是Android SDK提供的一个命令行工具,可以简单方便的发送随机的用户事件流,对Android APP做压力(稳定性)测试,主要是为了测试app是否存在崩溃与未响应等情况。目前在某些Android应用平台,新版app发布时,平台会执行monkey,检测APP是的稳定性、健壮性;1、通过adb 启动monkeya. 在cmd命令行执行:adb devices。 阅读详情

相关推荐

Android monkey命令和monkey脚本详解

是 Android 平台上一个非常有用的工具,它可以帮助开发者在设备上生成随机的用户事件流,如按键输入、触摸屏手势等,以此来测试应用的稳定性。Monkey 脚本是一种用于自动化 Android 设备上的随机事件生成的方法,这有助于测试应用程序的稳定性和健壮性。下面是一个简单的 Monkey 脚本示例,以及如何创建和执行这样的脚本。为了执行这个脚本,你需要确保你的设备已经连接到电脑并通过 ADB 进行调试。首先,在你的计算机上创建一个新的 Bash 脚本文件。这就是一个基本的 Monkey 测试脚本。

C'mon的博客 1866

【Monkey】

在android的官方自动化测试领域有一只非常著名的“猴子”叫Monkey,这只猴子一旦启动,就会让被检测得Android应用程序像猴子一样活蹦乱跳,到处乱跑,人们常用这只猴子来对呗测试的程序进行压力测试,检查和评估被测试程序的稳定性。Monkey是一个程序,运行在你的设备上,并生成随机的用户事件流,如点击,触摸或手势以及一些系统级事件,可以使用Monkey以随机但可重复的方式对你正在开发的应用程序进行压力测试。

fresh_xxy的博客 3391

影刀RPA进阶:Excel多条件筛选与数据提取实战

本文详细介绍了如何利用影刀RPA实现Excel多条件筛选与数据提取的自动化。通过拆解文本、数值、日期及颜色筛选等核心指令,并结合实战案例,指导用户构建稳健的销售数据提取机器人,从而高效处理复杂数据报表,提升工作效率。

onion的博客 527

monkey命令的使用

一、monkey的概念 Monkey是Android中的一个命令行工具,可以运行在模拟器里或者现实设备中,向系统发送伪随机的用户事件流(点击、滑动、Application切换、横竖屏、应用关闭)实现对正在开发的应用程序进行压力测试。monkey测试是一种为了测试软件的稳定性,健壮性的快速有效的方法,只针对Activity做测试,不能对Service做测试。 二、monkey的使用 1、运行原理 adb shell monkey 2、monkey的基本命令 1、help命令 adb shel

m0_59315964的博客 1万+

Claude Code 使用 OpenAI Codex(GPT-5.3-Codex)完整配置教程

通过 LiteLLM 可以让 Claude Code 调用任何模型,包括:OpenAIDeepSeekGemini本地模型↓↓优点:不依赖 Anthropic API可自由切换模型支持统一 AI Gateway这种“LLM Gateway 架构”正在成为 AI 开发工具的主流实践。

Jacobe_zhao的博客 1万+

微信小程序导航栏滑动一定距离后固定到顶部

接上一篇文章的内容,通常在一个页面中部会有一个导航栏查看不同的内容,这篇文章旨在实现在页面下滑的过程中导航栏自动固定到顶部以便我们阅读过程中的切换。 下滑一段距离后自动固定到顶部 首先,思考这个功能应该是怎么实现的: 在页面下滑的过程中,我们希望系统应当能识别下滑了多少距离,当原本的导航栏逐渐被遮住以后(遮住意味着下滑了特定距离),触发这个功能,执行另一种样式,将导航栏固定在页面顶端,同时如果我们将页面往上滑,系统能识别到原来的导航栏能露出来了(即距离顶端的高度小于一个特定的值),这时候又执行最初的样式

Oblivision_Geek的博客 4029

android压力测试命令monkey详解,android压力测试命令monkey详解

1、Monkey 是什么? Monkey 就是SDK中附带的一个工具。java2、Monkey 测试的目的? :该工具用于进行压力测试。 而后开发人员结合monkey 打印的日志 和系统打印的日志,结局测试中出现的问题。android3、Monkey 测试的特色? Monkey 测试,全部的事件都是随机产生的,不带任何人的主观性。shell4、Monkey 命令详解安全1).标准的monkey 命...

weixin_33238272的博客 173

共享最近邻相似度

共享最近邻相似度 第三十四次写博客,本人数学基础不是太好,如果有幸能得到读者指正,感激不尽,希望能借此机会向大家学习。本文作为基于图的聚类的第二部分,主要针对“共享最近邻相似度(Shared Nearest Neighbour)”以及使用该度量的“Jarvis-Patrick聚类”进行介绍。其他基于图的聚类算法的链接可以在这篇综述《基于图的聚类算法综述(基于图的聚类算法开篇)》的结尾找到。 S...

Ἥλιος 7606

详解:android- monkey命令

主要介绍了android monkey命令详解,Monkey 就是SDK中附带的一个工具,该工具主要用于进行压力测试: 一、Monkey 是什么? Monkey 就是SDK中附带的一个工具。   二、Monkey 测试的目的? 该工具用于进行压力测试。然后开发人员结合monkey 打印的日志和系统打印的日志,结局测试中出现的问题。   三、Monkey 测试的特点? Monkey

qwe19860的博客 368

win10离线安装.NetFrameWork3.5出现0x800F081F解决办法。

由于公司开发环境是内网,并且安装arcgis10.2又需要.NetFrameWork3.5的环境,安装.NetFrameWork3.5的又总是报错“0x800F081F”找不到源文件。折腾了两天总算解决了。 首先我们能在网上搜索到的教程,你一定看到过这样的教程,就是使用下面的命令来进行安装。 dism /online /Enable-Feature /Featu...

AIGIS的博客 1万+

YOLO11检测中的内存占用分析与优化:讲解如何分析并优化推理时的内存使用

YOLOv11模型内存分析与优化摘要:本文系统分析了YOLOv11目标检测模型的内存使用模式,重点探讨了显存(VRAM)、系统内存(RAM)和共享内存的特性差异。通过PyTorch内置工具和自定义分析器,详细剖析了骨干网络、颈部网络和检测头各组件内存占用规律,指出激活值内存与输入尺寸呈平方级增长关系。文章提供了卷积层内存计算公式,并强调合理规划"工作台"(显存)与"仓库"(内存)间的数据流动是优化关键。最后通过流程图直观展示了YOLOv11推理过程的三类内存使用模式,

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 343

android launcher详解_Android命令Monkey压力测试,详解

作者:糖小幽一、Monkey 是什么?Monkey 就是SDK中附带的一个工具。二、Monkey 测试的目的?该工具用于进行压力测试。 然后开发人员结合monkey 打印的日志 和系统打印的日志,结局测试中出现的问题。三、Monkey 测试的特点?Monkey 测试,所有的事件都是随机产生的,不带任何人的主观性。四、Monkey 命令详解1).标准的monkey 命令[adb shell...

weixin_39755003的博客 371

CDD数据库文件制作(十一)——服务配置(0x19_DTC Code)

虽然选择Copy和Reference都可以加载DTC,但是如果我们在DTC库中有修改DTC,通过Copy的方式加载的DTC在DTC Table中不会跟着DTC库的修改而自动更新。通过Reference的方式加载的DTC可以自动更新。找到Fault Memory的DTC Table,鼠标放在DTC Table区域,右键点击选择Copy …根据需要(客户协议)勾选响应的19服务子功能。如何创建一个新的DTC code?按照字母与下方要素可做一一对应。首先在DTC库中新建DTC。支持10 01/10 03。

LOVE135149的博客 1917

android压力测试命令monkey详解

这篇文章主要介绍了android monkey命令详解,Monkey 就是SDK中附带的一个工具,该工具主要用于进行压力测试,需要的朋友可以参考下 一、Monkey 是什么? Monkey 就是SDK中附带的一个工具。 二、Monkey 测试的目的? :该工具用于进行压力测试。 然后开发人员结合monkey 打印的日志 和系统打印的日志,结局测试中出现的问题。 三、Monk

快乐&&平凡 1475

LabVIEW实现TCP通信

在本节中,我们将简要探讨TCP通信的基础知识,并以工业物联网平台TLINK中的云端设备数据发布设计为例,详细阐述在互联网环境下TCP客户端应用程序设计的基本方法。

不脱发的程序猿 1959

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

android压力测试命令monkey详解【转】

本文转载自:http://www.jb51.net/article/48557.htm 作者: 字体:[增加减小] 类型:转载 时间:2014-03-29我要评论 这篇文章主要介绍了android monkey命令详解,Monkey 就是SDK中附带的一个工具,该工具主要用于进行压力测试,需要的朋友可以参考下 一、Monkey 是什么?Monkey 就是SDK中附带的一个工具。 二...

zzb2760715357的博客 121

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Android命令Monkey压力测试,详解,安卓面试题pdf下载

包之后,Monkey将只允许系统启动指定的APP。如果不指定包,Monkey将允许系统启动设备中的所有APP。 * 指定一个包: adb shell monkey -p com.htc.Weather 100 说明:com.htc.Weather为包名,100是事件计数(即让Monkey程序模拟100次随机用户事件)。 * 指定多个包:adb shell monkey -p com.htc.Weather –p com.htc.pdfreader  -p com.htc.photo.wi

m0_64603776的博客 188

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

上一篇: Android 8.0安装apk
下一篇: 多选题评分算法原理
github_2011
博客等级 码龄10年 116粉丝 56原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值