当前位置: 首页 > 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;例如…...

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…...

测试微信模版消息推送

进入“开发接口管理”--“公众平台测试账号”&#xff0c;无需申请公众账号、可在测试账号中体验并测试微信公众平台所有高级接口。 获取access_token: 自定义模版消息&#xff1a; 关注测试号&#xff1a;扫二维码关注测试号。 发送模版消息&#xff1a; import requests da…...

从零实现富文本编辑器#5-编辑器选区模型的状态结构表达

先前我们总结了浏览器选区模型的交互策略&#xff0c;并且实现了基本的选区操作&#xff0c;还调研了自绘选区的实现。那么相对的&#xff0c;我们还需要设计编辑器的选区表达&#xff0c;也可以称为模型选区。编辑器中应用变更时的操作范围&#xff0c;就是以模型选区为基准来…...

Mybatis逆向工程,动态创建实体类、条件扩展类、Mapper接口、Mapper.xml映射文件

今天呢&#xff0c;博主的学习进度也是步入了Java Mybatis 框架&#xff0c;目前正在逐步杨帆旗航。 那么接下来就给大家出一期有关 Mybatis 逆向工程的教学&#xff0c;希望能对大家有所帮助&#xff0c;也特别欢迎大家指点不足之处&#xff0c;小生很乐意接受正确的建议&…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

前端导出带有合并单元格的列表

// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

连锁超市冷库节能解决方案:如何实现超市降本增效

在连锁超市冷库运营中&#xff0c;高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术&#xff0c;实现年省电费15%-60%&#xff0c;且不改动原有装备、安装快捷、…...

如何将联系人从 iPhone 转移到 Android

从 iPhone 换到 Android 手机时&#xff0c;你可能需要保留重要的数据&#xff0c;例如通讯录。好在&#xff0c;将通讯录从 iPhone 转移到 Android 手机非常简单&#xff0c;你可以从本文中学习 6 种可靠的方法&#xff0c;确保随时保持连接&#xff0c;不错过任何信息。 第 1…...

基于Docker Compose部署Java微服务项目

一. 创建根项目 根项目&#xff08;父项目&#xff09;主要用于依赖管理 一些需要注意的点&#xff1a; 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件&#xff0c;否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...

用docker来安装部署freeswitch记录

今天刚才测试一个callcenter的项目&#xff0c;所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...