当前位置: 首页 > news >正文

【App自动化测试】(十六)健壮性测试工具——Android Monkey

目录

  • 1. 介绍
  • 2. 安装
  • 3. Monkey的使用
  • 4. money常用命令
  • 5. 常用事件类型参数
  • 6. Monkey使用参考


1. 介绍

  • Monkey是一个在模拟器或设备上运行的程序,用于生成用户事件的伪随机流。

    为什么要使用Monkey这个自动化遍历工具?

    Monkey解决了一个测试痛点:当手工测试过程中,一个页面存在非常多的元素,比如雪球APP可能一个面中有10万支股,每支股中又包含非常多的小数据,如果我们正向的自动化测试的话,编写自动化测试用例就会耗时很久,如果我们使用手工测试的话工作量也会非常庞大。使用Monkey的话可以在不用编程或者编写很少的代码和参数的情况下,完成随机点的效果,从而节省人力和物力。

  • Monkey优点:速度最快,编码少,甚至不要编码

  • Monkey缺点:随机发生,不收控制

2. 安装

  • Android SDK自带了Monkey工具

    • 配置Android SDK环境变量后即可使用Monkey
    • 在真机或移动设备中同样可以使用Monkey

3. Monkey的使用

adb shell monkey [options] [事件计数]

  • 基本配置选项,例如设置事件数量
  • 操作约束,例如对指定App进行测试
  • 事件类型和频率,例如提高点击事件发生频率
  • 调试选项,包括一些其他参数

4. money常用命令

  • 对所有包进行随机操作:adb shell monkey [事件次数]
  • 对指定包进行随机操作:adb shell monkey -p [包名] [事件次数]
    • -p:指定包名参数
  • 随机种子:adb shell monkey -p [包名] -s [种子值] [事件次数]
    • -s:时间种子参数
    • 参数说明:随机种子可以让每次生成的随机事件都一样的。比如说我上一次生成了80个点击事件,那么下一次很有可能生成了80个滑动事件,如果想让每次生成随机的事件都是一样的,那么可以加上随机种子参数。Monkey内部有一个算法可以根据20计算出固定的随机时间,比如说我第一次 -s 20 80,可能生成了80个点击事件,那么下一次再使用 -s 20 80,他还会生成和之前一样的80个点击事件。
  • 详细日志:adb shell monkey -p [com.xueqiu.android] -vv -s [20] [100]
    • -vv:详细monkey日志
  • 时间延迟:adb shell monkey -p [com.xueqiu.android] -vv --throttle [延迟时间:毫秒] [事件次数]
    • --throttle:延迟时间参数
  • 事件百分比:adb shell monkey -p [com.xueqiu.android] -vv [options:事件类型] [百分比:1~100] [总事件次数]
    • 说明:例如 --pct-touch 10 :将触摸事件的百分比提高到10%

5. 常用事件类型参数

  • 触摸事件(例如:点击):--pct-touch
  • 动作事件(例如:直线滑动):--pct-motion
  • 轨迹时间(例如:移动+点击;曲线滑动):--pct-trackball
  • 主要导航事件(例如:退回按键;菜单按键):--pct-majornav

6. Monkey使用参考

  • monkey -h

    usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...][-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...][--ignore-crashes] [--ignore-timeouts][--ignore-security-exceptions][--monitor-native-crashes] [--ignore-native-crashes][--kill-process-after-error] [--hprof][--pct-touch PERCENT] [--pct-motion PERCENT][--pct-trackball PERCENT] [--pct-syskeys PERCENT][--pct-nav PERCENT] [--pct-majornav PERCENT][--pct-appswitch PERCENT] [--pct-flip PERCENT][--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT][--pct-permission PERCENT][--pkg-blacklist-file PACKAGE_BLACKLIST_FILE][--pkg-whitelist-file PACKAGE_WHITELIST_FILE][--wait-dbg] [--dbg-no-events][--setup scriptfile] [-f scriptfile [-f scriptfile] ...][--port port][-s SEED] [-v [-v] ...][--throttle MILLISEC] [--randomize-throttle][--profile-wait MILLISEC][--device-sleep-time MILLISEC][--randomize-script][--script-log][--bugreport][--periodic-bugreport][--permission-target-system]
    
  • android studio 官方文档

    CategoryOptionOption
    General--helpPrints a simple usage guide.
    -vEach -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, andfinal 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-randommovements, 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 asthe 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 maximizingcoverage 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-usedbuttons on the device, and so forth.
    Constraints-p <allowed-package-name>If you specify one or more packages this way, the Monkey willonlyallow the systemto visit activities within those packages. If your application requires access to activities inother 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 activitiesin 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 willonlyallow 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 categoryIntent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -coption multiple times — one -c option per category.
    Debug--dbg-no-eventsWhen specified, the Monkey will perform the initial launch into a test activity, butwill not generate any further events.For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkeyrunning for 30 seconds or more. This provides an environment in which you can monitor packagetransitions invoked by your application.
    --hprofIf set, this option will generate profiling reports immediately before and afterthe Monkey event sequence.This will generate large (~5Mb) files in data/misc, so use with care. SeeTraceviewfor more informationon trace files.
    --ignore-crashesNormally, 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 tothe system, until the count is completed.
    --ignore-timeoutsNormally, the Monkey will stop when the application experiences any type of timeout error suchas 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-exceptionsNormally, 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 specifythis option, the Monkey will continue to send events to the system, until the count is completed.
    --kill-process-after-errorNormally, when the Monkey stops due to an error, the application that failed will be leftrunning. When this option is set, it will signal the system to stop the process in which the erroroccurred.Note, under a normal (successful) completion, the launched process(es) are not stopped, andthe device is simply left in the last state after the final event.
    --monitor-native-crashesWatches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop.
    --wait-dbgStops the Monkey from executing until a debugger is attached to it.

相关文章:

【App自动化测试】(十六)健壮性测试工具——Android Monkey

目录 1. 介绍2. 安装3. Monkey的使用4. money常用命令5. 常用事件类型参数6. Monkey使用参考 1. 介绍 Monkey是一个在模拟器或设备上运行的程序&#xff0c;用于生成用户事件的伪随机流。 为什么要使用Monkey这个自动化遍历工具&#xff1f; Monkey解决了一个测试痛点&#xff…...

实现第一个内核程序的Hello World

背景 在内核的开发中&#xff0c;总要先入个门。那么就要来编写第一个内核程序 入门 一个 module_init 程序是Linux内核模块的一部分&#xff0c;通过module_init 方法就能将程序载入内核。 module_init 方法需要以下步骤 编写module_init 的代码&#xff0c;并将其保存为…...

python基于协同过滤推荐算法的电影观后感推荐管理系统的设计

本课题所设计的影单管理系统&#xff0c;使用B/S架构&#xff0c;Python语言进行开发&#xff0c;它的优点代码不能从浏览器查看&#xff0c;保密性非常好&#xff0c;比其他的影单管理更具安全性。Python还容易修改和调试&#xff0c;毕竟影视是在不断发展过程中&#xff0c;难…...

Vue——状态管理库Pinia

写在前面&#xff1a;本文参考小满大牛的pinia专栏 一、Vuex与Pinia Vuex 和 Pinia 均是 Vue.js 的状态管理库&#xff0c;它们为 Vue 应用程序提供了一种集中式的、可预测的状态管理解决方案。 Vuex 是 Vue.js 官方推荐的状态管理库之一。它的核心概念包括 state、mutation…...

Linux:忘记root密码解决办法

如果你是虚拟机只要将光盘镜像连接到虚拟机上&#xff0c;以光盘iso镜像启动 如果你是真机或服务器那将实体u盘或实体光盘连接至设备并且以连接的设备启动 开机时候打断开机 使用 &#xff08;u盘|光盘&#xff09;引导启动 troubleshooting rescue a centos system 输入 1…...

Dockerfile(4) - RUN 指令详解

RUN 运行命令 shell 形式 命令在 shell 中运行Linux 上默认为 /bin/sh -cWindows 上 cmd /S /C RUN <command> exec 形式 RUN ["executable", "param1", "param2"] 必须双引号&#xff0c;不能是单引号 两种写法的实际栗子 RUN …...

一个完整的APP定制开发流程是怎样的?

随着移动互联网的发展&#xff0c;越来越多的 APP应用软件进入人们的生活&#xff0c;让我们的生活更便捷、更舒适。而随着互联网技术的进步&#xff0c;移动互联网应用软件开发行业也越来越成熟&#xff0c;为了适应市场需求&#xff0c;各种功能强大、性能良好的 APP应用软件…...

【数据结构】24王道考研笔记——线性表

线性表 目录 线性表定义和基本操作顺序表静态顺序表动态顺序表 链表单链表不带头结点&#xff1a;带头结点&#xff1a; 双链表循环链表循环单链表&#xff1a;循环双链表&#xff1a; 静态链表 顺序表链表比较逻辑结构&#xff1a;存储结构&#xff1a;基本操作&#xff1a; 定…...

【Linux C】基于树莓派/香橙派的蓝牙服务端——支持多蓝牙设备接入

一、需求 在树莓派/香橙派上利用开发板自带的蓝牙作为一个蓝牙服务端&#xff08;主机&#xff09;&#xff0c;允许外来设备&#xff08;从机&#xff09;通过蓝牙接入进行通信&#xff0c;通信格式为透传方式&#xff1b;采用的编程语言为Linux C 二、环境准备 bluez安装 …...

鸿蒙App开发选择Java还是JavaScript?

众所周知&#xff0c; Java和 JavaScript是两种编程语言&#xff0c;这两种语言在不同的环境中都有许多用途。在鸿蒙 App开发中&#xff0c; Java和 JavaScript是两种常见的编程语言&#xff0c;它们都具有广泛的应用&#xff0c;并且都有其独特的优势。下面我们将就这两种编程…...

【Android】CountDownTimer的使用

android中怎么实现倒计时 在Android中&#xff0c;可以使用CountDownTimer类来实现倒计时。以下是一个简单的示例&#xff1a; javaCopy new CountDownTimer(30000, 1000) {public void onTick(long millisUntilFinished) {// 每次倒计时间隔1秒&#xff0c;更新UI上的倒计时剩…...

Linux :: 【基础指令篇 :: 文件及目录操作:(1)】:: ls :: 查看指定目录下的内容

前言&#xff1a;本篇是 Linux 基本操作篇章的内容&#xff01; 笔者使用的环境是基于腾讯云服务器&#xff1a;CentOS 7.6 64bit。 学习集&#xff1a; C 入门到入土&#xff01;&#xff01;&#xff01;学习合集Linux 从命令到网络再到内核&#xff01;学习合集 目录索引&am…...

【商品详情 +关键词搜索】API 接口系列

首先&#xff0c;大家要到官方主页去申请一个 appkey&#xff0c;这个是做什么用的呢&#xff1f;App Key 是应用的唯一标识&#xff0c;TOP 通过 App Key 来鉴别应用的身份。AppSecret 是 TOP 给应用分配的密钥&#xff0c;开发者需要妥善保存这个密钥&#xff0c;这个密钥用来…...

RabbitMQ学习-发布确认高级

发布确认springboot版本 确认机制方案&#xff1a; 代码架构图&#xff1a; 配置文件&#xff1a; 在application.properties全局配置文件中添加spring.rabbitmq.publish-confirm-type属性&#xff0c;这个属性有以下几种值 none:禁用发布确认模式(默认)0 correlated:发布消…...

重载和内联函数

函数的默认参数 默认参数是指调用函数的时候&#xff0c;如果不写实参&#xff0c;那么将使用一个缺省值。 使用默认参数可以使你的函数更加灵活&#xff0c;同时减少了在不同上下文中为相同的参数重复编写相同的代码的需要。 return_type function_name(data_type paramete…...

从零学算法

198.你是一个专业的小偷&#xff0c;计划偷窃沿街的房屋。每间房内都藏有一定的现金&#xff0c;影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统&#xff0c;如果两间相邻的房屋在同一晚上被小偷闯入&#xff0c;系统会自动报警。 给定一个代表每个房屋存放金额…...

《Linux0.11源码解读》理解(四) head之重新设置IDT/GDT

上节提到&#xff0c;现在cs:ip指向0地址&#xff0c;此处存储着作为操作系统核心代码的system模块&#xff0c;是由head.s和 main.c以及后面所有源代码文件编译链接而成。head.s(以下简称head)紧挨着main.c&#xff0c;我们先执行head。 重新设置内核栈 _pg_dir: _startup_3…...

<SQL>《SQL命令(含例句)精心整理版(4)》

《SQL命令&#xff08;含例句&#xff09;精心整理版&#xff08;4&#xff09;》 14 数据库对象14.1 表14.2 视图14.3 存储过程14.3.1 概念14.3.2 创建存储过程14.3.2 调用存储过程14.3.3 DbVisualizer工具中调用方法14.3.3 DB2命令行脚本调用方法14.3.4 DB2中两个存储过程报错…...

C++死锁

死锁是指两个或两个以上的线程在执行过程中&#xff0c;由于竞争资源或者由于彼此通信而造成的一种阻塞的现象&#xff0c;若无外力作用&#xff0c;它们都将无法推进下去。此时称系统处于死锁状态或系统产生了死锁&#xff0c;这些永远在互相等待的状态称为死锁。 死锁通常发生…...

[自学记录02|百人计划]纹理压缩

一、什么是纹理压缩 纹理压缩是为了解决内存、带宽问题&#xff0c;专为在计算机图形渲染系统中存储纹理而使用的图像压缩技术。 1.图片格式和纹理格式的区别 (1)图片格式 图片格式是图片文件的存储格式&#xff0c;通常在磁盘、内存中储存和传输文件时使用&#xff1b;例如…...

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; &#x1f680; AI篇持续更新中&#xff01;&#xff08;长期更新&#xff09; 目前2025年06月05日更新到&#xff1a; AI炼丹日志-28 - Aud…...

51c自动驾驶~合集58

我自己的原文哦~ https://blog.51cto.com/whaosoft/13967107 #CCA-Attention 全局池化局部保留&#xff0c;CCA-Attention为LLM长文本建模带来突破性进展 琶洲实验室、华南理工大学联合推出关键上下文感知注意力机制&#xff08;CCA-Attention&#xff09;&#xff0c;…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器

一.自适应梯度算法Adagrad概述 Adagrad&#xff08;Adaptive Gradient Algorithm&#xff09;是一种自适应学习率的优化算法&#xff0c;由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率&#xff0c;适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...

五年级数学知识边界总结思考-下册

目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解&#xff1a;由来、作用与意义**一、知识点核心内容****二、知识点的由来&#xff1a;从生活实践到数学抽象****三、知识的作用&#xff1a;解决实际问题的工具****四、学习的意义&#xff1a;培养核心素养…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...

HBuilderX安装(uni-app和小程序开发)

下载HBuilderX 访问官方网站&#xff1a;https://www.dcloud.io/hbuilderx.html 根据您的操作系统选择合适版本&#xff1a; Windows版&#xff08;推荐下载标准版&#xff09; Windows系统安装步骤 运行安装程序&#xff1a; 双击下载的.exe安装文件 如果出现安全提示&…...

前端开发面试题总结-JavaScript篇(一)

文章目录 JavaScript高频问答一、作用域与闭包1.什么是闭包&#xff08;Closure&#xff09;&#xff1f;闭包有什么应用场景和潜在问题&#xff1f;2.解释 JavaScript 的作用域链&#xff08;Scope Chain&#xff09; 二、原型与继承3.原型链是什么&#xff1f;如何实现继承&a…...

稳定币的深度剖析与展望

一、引言 在当今数字化浪潮席卷全球的时代&#xff0c;加密货币作为一种新兴的金融现象&#xff0c;正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而&#xff0c;加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下&#xff0c;稳定…...