03 - Jmeter用户自定义变量CSV参数化以及断言的设置
2019-11-08 本文已影响0人
Tourble
设置断言
咱们还是先看一个图吧,由下图可以看出接口是请求成功了,但是请求数量比较少,还是比较方便看的,但是jmeter既然是压测工具,那么肯定不会发这么点儿请求的,如果请求数量比较庞大的话,我们仅仅凭借肉眼是很难看出的;这就需要我们运用的到其他的功能了;断言

增加断言的方式 以及页面介绍
HTTP Request → add → Assertios → Response Assertions
- Apply to 应用范围
Main sample only:仅当前父取样器进行断言,一般一个请求
Sub sample only: 一个请求触发多个,比较少用 - Field to Test 要测试响应的字段
Test Response:响应文本
Response Code:响应代码
Response Message:响应信息
Response Headers: 响应消息头
Request Headers:响应请求头 - Pattern Matching Rules 匹配内容的方式
Contains:包含
Matches:匹配
Equals:相等
Substring:匹配字符串 - Patterns to Test 测试模式
-
Custom failure message 自定义失败消息
2.jpg
然后咱们就随便加一个断言试一下
此接口内容包含了请求成功,但是我们想让接口触发断言,故而不能用请求成功来匹配



自定义用户变量
这里关于自定义变量如何使用,为什么用就不解释了,就来说一下局部和(全局)吧
- 局部变量自定义变量创建及介绍
HTTP Request → addt → Config Elementt → User defined Varibles
name:变量名
value:变量值
description:说明 - 全局变量自定义
测试计划右侧



CSV参数化操作
在压测服务器时,如果只用一些固定的数据肯定是不可行的,我们需要做的就是,尽可能的模拟生产环境的真实使用场景,所以这里就提到了另外一个组件 CSV set data config(csv 数据文件设置)

File Name:文件名
File encodding:文件编码
Varible Names:引用时需要用的变量名
Igore first line:忽略首行 (false)
Delimiter:参数的分隔符
Allow quoted data:是否允许带引号 (false)
Recycle on EOF:遇到文件结束符时再次循环 (true)
Stop thread on EOF:遇到文件结束符停止线程 (false)
Sharing mode:线程共享模式,(全局,当前线程组,当前线程)
txt文件测试
参考下图,文件和CSV配置;咱们模拟了三个账号来登录,so线程组设置为3次




CSV文件测试 以及多个变量
多个变量定义用逗号隔开切记不要有空格,包括文件内容也是以逗号隔开,引用方式与文本是一致的
