Performance testing tool---jmeter explanation

1. The directory structure of jmeter

bin 目录(常用文件介绍)
    jmeter.bat:windows下启动文件
    jmeter.sh:Linux下启动文件
    jmeter.log:Jmeter运行日志文件
    jmeter.properties:Jmeter配置文件
/docs目录——Jmeter帮助文档
/lib/ext目录——存放Jmeter依赖的jar包

2. Function overview

2.1 Sinicization

2.2 Modify the theme

3. jmeter components and components

3.1 Basic introduction of components

Component: A container for multiple similar functional components (similar to a class)

3.2 Basic introduction of components

Component: implement an independent function (similar to a method)

 summary:

3.3 Scope of components

The scope of the component: is determined by the parent-child relationship of the component in the tree structure of the test plan 

Tip: All components run on the core of the sampler . The location where the component is added is different, and the effective sampler page is different

 Execution order of elements:

(1) Different components under the same scope:

     Configuration elements, preprocessors, timers, samplers, postprocessors, assertions, listeners

(2) The same components under the same scope:

     Execute sequentially from top to bottom

case:

 Execution order:

Timer 1--http request 1--timer 1--timer 2--http request 2--timer 1---timer 3--http request 3

4. Example of using jmeter

4.1 Thread Group

作用: 线程组就是控制jmeter用于执行测试的一组用户
位置: 右击"测试计划"-->添加-->线程(用户)-->线程组
特点: 
     模拟多人操作
     线程组可以添加多个,多个线程组可以并行或者串行
     取样器和逻辑控制器必须依赖线程组才能使用
     线程组可以添加其他元组下组件

4.1.1 Classification of thread groups

普通线程组,常用的线程组,可以看做是一个虚拟用户组,线程组中的每一个线程都可以理解为一个虚拟用户
setup线程组:一种特殊类型的线程组,可用于执行预测试操作
teardown线程组:一种特殊类型的线程组,可用于执行测试后工作

4.2 HTTP requests

作用: 向服务器发送http请求和https请求
位置: 进入线程组-->右击-->添加-->取样器-->HTTP请求

4.3 Listeners

作用: 监听器可以动态的监控jmeter测试执行的过程,实时查看测试结果
位置: 线程组-->添加-->监听器-->聚合报告/察看结果树

 (1) View the result tree

(2) Aggregate report

 Five. jmeter parameterization

5.1 Introduction to jmeter

本质:使用参数的方式替代脚本中的固定的测试数据
实现方式:文件定义的方式/数据库的方式/定义变量

5.2 jmeter parameterization

Parameterized test: organize the test data and call the same test method with different test data.

Common parameterization methods in jmeter:

用户定义的变量
用户参数
CSV Data Set Config
函数

5.2.1 User-defined variables

作用: 定义全局变量

位置: 测试计划-->线程组-->配置元件-->用户定义的变量

 Need to be referenced by ${variable name}

5.2.2 User parameters

作用: 针对同一组参数,当不同的用户来访问时,可以获取到不同的值
位置: 测试计划-->线程组-->前置处理器-->用户参数

5.2.3 CSV data file settings

作用: 让不同的用户在多次循环时,可以取到不同的值
位置: 线程组-->配置元件-->csv数据文件设置

 

5.2.4 Function parameterization

作用: 计数函数,一般做执行次数统计使用

Method 1: _counter function

Location: Options --> Function Comments Dialog -->_counter

Method 2: CsvRead function

Location: Options-->Function Comment Dialog-->CsvRead

 Method 3: RandomString function

Location: Options --> Function Comments Dialog -->_RandomString

 Six. jmeter assertion

effect:

让程序判断预期结果和实际结果是否一致

 Common assertions:

响应断言
json断言
xpath断言

6.1 Response assertions

作用:对http请求的任意格式的响应结果进行判断
位置:测试计划-->线程组-->http请求-->(右键添加)断言-->响应断言

 6.2 JSON assertion

作用:对http请求的json的响应结果进行判断
位置:测试计划-->线程组-->http请求-->(右键添加)断言-->json断言

 6.3 xpath assertion

定义:xpath基于XML的树状结构,提供在数据结构树中寻找节点的能力
位置:测试计划-->线程组-->http请求-->(右键添加)断言-->xpath断言

区别:
    响应断言(适用任何的返回类型),
    json断言(只适用于json的返回类型),
    Xpath断言,针对返回信息为Xpath的数据类型进行断言

6.4 Assertion Duration

作用:检查http请求的响应时间是否超出要求范围
位置:测试计划-->线程组-->http请求-->(右键添加)断言-->断言持续时间

Seven. jmeter association

Common associations:

正则表达式提取器 --提取任意格式的数据
json提取器 --提取json格式的数据
xpath提取器 --提取html格式的数据

7.1 Regular expressions

作用:针对任意格式的响应数据进行提取
位置:线程组>>添加>>后置处理器>>正则表达式提取器
公式格式:左边界(匹配符号)有边界:可以提取出想要获取的数据内容
.:是通配符,可以代表任意字符(除换行回车)
*:代表前面的字符出现0或者多次
.*匹配规则:找到左边界值后,往右查找有边界,找到最后面的有边界,中间的所有的数据都被记录下来
?:代表非贪婪匹配,找到左边界后,往右查找匹配走边界,只要右匹配的右边界就停止继续查找;再次查找
左边界的右边界
公式格式:左边界(.*?)有边界
<title>(.*?)</title>
<title>百度一下,你就知道</title>

 Detailed parameters

引用名称:存放提取出的值的参数名称
正则表达式:左边界(.*?)有边界
模板:用$$引用起来,表示解析出第几组()的值
匹配数字:1表示第一个值,-1表示所有的取值

  

  

  

7.2 json extractor

json提取器 :就是json表达式提取数据,从返回格式是json中提取想要的数据内容
位置:线程组>>添加>>后置处理器>>json提取器

 case:

Realize login--query balance

 Extract the login token data through json expression

 balance interface

 7.3 xpath extractor

xpath提取器 :针对于HTML格式的响应结果数据进行提取
位置:线程组>>添加>>后置处理器>>xpath提取器

 case:

Extract data in Baidu search, pass the second Baidu search to search

 verify

 Use on the second interface

注意:
    正则可以适用任何形式的返回格式类型,
    json可以适用于json格式的返回类型,
    xpath适用html格式的返回类型

Guess you like

Origin blog.csdn.net/qq_44954371/article/details/126858087