一、
1、优点:
(1)开源
(2)跨平台
(3)支持多协议
2、缺点
(1)不支持ip欺骗
(2)使用JMeter无法验证JS程序,也无法验证页面UI
3、性能指标(TPS QPS RPS形容服务器,HPS形容客户端(用户每秒点击率))
(1)虚拟用户数
(2)并发数
(3)事务
(4)场景:性能测试的用例
(5)响应时间
(6)TPS:一定时间能处理的事务数(如果事务只有一个接口,TPS=吞吐量)
(7)QPS:每一秒的查询率(针对查询接口,增删改跟他没关系,一般是用来描述数据库的)
(8)吞吐量:衡量网络成功传输的数量
(9)资源利用率:CPU 内存 硬盘 网络
4、性能测试分析
(1)需求分析以及需求确定(指标值、场景、环境、人员)
(2)性能测试计划和方案制定(基准测试,负载测试,压力测试,稳定测试等)
(3)性能测试准备(人力,硬件,软甲,环境折算)
(4)测试执行
(5)测试报告,测试总结
5、接口测试
(1)拿到api接口文档,熟悉接口业务,地址、端口、错误码等
(2)编写接口测试用例以及评审
正例(对内部系统):
(2.1)输入正常的参数,验证接口能够正常返回
反例(对外部系统):
(2.2.1)鉴权异常:为空,错误,过期
(2.2.2)参数异常:为空,长度异常,类型异常,其他业务异常
(2.2.3)其他异常:黑名单,调用次数限制,分页场景
(2.2.4)兼容异常:一个接口被多端调用
(3)使用接口测试工具
(4)输出报告
6、JMeter组件
(1)测试计划:JMeter测试的起点,容器
(2)线程组:代表一定的用户
(3)配置原件:配置请求
(4)前置处理器:请求之前的操作
(5)定时器:演示请求
(6)逻辑控制器:处理请求逻辑
(7)取样器:发送请求的最小单元
(8)后置处理器:请求之后的操作
(7)断言:判断请求结果是否正常
(10)监听器:收集测试结果
7、组件的作用域
(1)组件可以作用于同级组件
(2)组件可以作用于同级组件下的子组件
(3)组件可以作用于父组件
8、JMeter的使用
(1)新增线程组

(2)添加配置组件

(3)基本的这三个需要加上

(4)添加控制器(我们这里添加简单的控制器)

(5)控制器里面添加请求(取样器)

(6)增加监听器(线程组,控制器,取样器下面都可以加)

(7)目前状态栏

9、目前市面上的三类接口
(1)基于webservice协议接口,通过xml传输数据(比较老)
(2)基于dubbo协议接口,通过json传输数据(微服务)
(3)基于http协议接口(Restful大部分是这种协议),传输json数据(最多)
10、http协议:请求和响应
(1)请求:请求方式,请求路径,请求头,请求数据
(2)响应:响应码,响应信息,响应头,响应数据
11、接口约定
(1)请求数据通过json格式传递,需要添加一下请求头
列如:Content-Type:application/json(Postman默认是这样的,Jmeter需要我们手动设置)
(2)除注册登录接口外,请求时需要提供token
(3)token通过登录获取,需要添加以下请求头
列如:Authorization:Bearer abc 其中abc为token值
(4)2XX状态码表示请求成功
(5)4XX状态码表示请求失败,并通过detail字段返回原因
12、禁用线程组

13、注册接口
(1)添加个http请求

(2)给我们创建的http请求设置默认参数(http默认端口80,https443)根据测试文档请求进行设置,这里给的参数只是举例,每个测试不一样

(3)设置请求头

(4)根据我们的需求对我们的内容进行填写
(5)都设置完我们可以进行测试

14、登录接口这些接口跟我们的项目而定,项目不同接口不同(如果没有接口文档我们的部分测试可以通过抓包来定)
15、我们除了注册和登录接口外其他接口都需要添加token(要注意好作用域,将我们的请求头放在我们要测的请求下面)

17、接口关联(我们的查询接口需要从登录接口获得token值)
(1)正则表达式提取器

(2)JSON提取器
(3)配置(正则)

(3.1)内容讲解
(3.1.1)变量名:随意定义
(3.1.2)正则表达式:要包括有左边界和右边界以及(.*?),而且必须唯一
(3.1.3)1表示取第一个正则,2表示取第二个正则
(3.1.4)匹配数字:表示取第一个匹配到的值
(3.1.5)默认值:表示没有匹配到就用默认值

(4)查看我们的刚才的操作取没取到,添加调试取样器

(5)调试取样器查看

(6)在我们的接口信息头中添加我们取到的token

(7)也可以匹配多个正则
如果像这种写法我们还可以把我们请求头进行删减(去掉了Bearer这个从我们的关联接口中获取)
(8)配置(JSON)
(8.1)语法格式:表示根目录,**.** 表示子节点,.access_token表示获取token的值 ,取数组的值通过[下标],下标从0开始
(8.2)token取值演示($.*表示取所有值)

(8.3)举例取值(id=189):.data.goods_list\[0\].goods_items\[0\].id(看到{}用. 看到[] 用[下标])

(8.4)创建JSON提取器

(8.5)提取器设置
(8.6)JSON规则
(8.6.1)变量名
(8.6.2)jsonpath表达式(只能取一个不能跟正则一样写多个)
(8.6.3)匹配数字,表示取第一个匹配到的值
(8.6.4)默认值,没有匹配到就使用默认值
(8.7)我们可以在创建一个取Bearer值(用这种方法在信息头中获取两者)

(8.8)目前项目栏

(8.9)如果出现中文乱码(加编码格式)

18、我们要进行修改操作时候我们用到PUT请求,我们需要获取到相应的id才能进行更改
(1)提取

(2)获取(直接在消息体中修改就可以)

19、删除接口

20、测试接口要实现一个业务闭环:不能测试完接口多了或少了id之类的内容
21、我们url的内容可以这样展示,可以这样写

22、文件上传(两个\\可以换成一个/)

23、我们要注意我们的有的标签名只能出现一次(比如name'广东人',运行一次后,有了广东人,在运行就会报错)
24、函数工具,为了应对23的name标签重复(加随机数的函数)
(1)

(2)
(3)

25、如果我们的生成树太快太频繁我们可以增加一个定时器

设置两秒定时

26、如果给我们指定端口我们就不用管443或80了,直接用指定的

27、重要加密网站:https://www.bejson.com/
28、AES,DES,Base64,RSA (可以解密),MD5,SHA,HmacSHA(不能解密)
29、加密接口的实现
(1)生成加密函数(MD5方式)

(2)带入加密后的函数
(3)用其他方法加密(举例SHA)

(4)举例Base64
30、获取token
(1)首先把日志打开

(2)后置处理器


然后在日志处查看token,也可以写成String token = vars.get("access_token"); log.info(token)
31、token是可以通过cookie传播的
32、Http cookie管理器实现cookie关联的原理(默认:作用域在同级别的组件)
(1)当Jmeter第一次请求服务器的时候,如果说服务器有通过响应头的Set-Cookie有返回cookie,那么Http cookie管理器就会自动保存这些cookie的值
(2)然后当Jmeter第二次以后请求服务器的时候,那么Http cookie管理器会自动的把保存的这些cookie通过请求头的cookie字段传输给服务器,从而实现cookie管理
33、cookie实现接口

34、增加断言(常用)

35、断言的使用(响应里面有seccess就成功,没有就失败)
(1)响应断言

(2)JSON断言(判断state内容是否是success)

(3)响应断言状态码
36、接口测试CSV参数化(做正反例测试时候用)
(1)增加反例

(2)首先构建我们的数据类

(3)将我们刚才创建的CSV文件添加进来

(4)设置好我们的CSV文件
(5)我们刚才写死的参数就不能写死了

(6)设置循环控制器:因为我们有三组用例所以我们要循环三次

(7)有多少数据循环多少次
(8)增加个断言判断state

37、接口测试调试
(1)调试取样器(作用就是能够看到全局变量)
(2)看请求和响应的四要素(请求体,请求头,响应体,响应头)
38、Jmeter的非GUI命令行的执行
(1)jmeter -n -t test.jmx (-n非GUI的方式 -t指定需要执行的脚本)
(2)生成jtl报告 jmeter -n -t test.jmx -l result.jtl
(3)生成html文件 jmeter -n -t test.jmx -l result.jtl -e -o results 注意:修改全局配置文件jmeter.propties 中的 jmeter.save.savesrevice.output_format=csv