当前位置:网站首页>Implementation and design of JMeter interface test database assertion for CSDN salary increase technology
Implementation and design of JMeter interface test database assertion for CSDN salary increase technology
2022-06-13 01:35:00 【Test Architect Bei fan】
Preface :
Most interface tests use the response value of the interface as the basis for interface verification , However, in the interface interacting with the database, this result judgment is not enough to judge the correctness of the interface , This article will be jmeter As a tool for interface testing to implement the database assertion of the interface
【 The end of the article leaves a lot of benefits for everyone 】

One 、 Overview of the general idea
- Use jmeter Initiate interface request
- Use json The extractor obtains the key content in the interface response result
- Use jmeter Initiate database operation , Get the value of the database
- Use BeanShell Assertion , Realize the comparison between interface response content and database content
Two 、jmeter Initiate interface request
Take the search interface for example , Business requirements are : Search for products through keywords . The interface information is as follows :
Interface information :

Input parameters :

Return results :


According to the above interface information, in jmeter Add http request , Here's the picture

3、 ... and 、 Add... For interface request json Extractor
add to json The extractor is to get all the data in the interface response name, Used to compare with... Found in the database name Compare the values one by one
1. add to json Extractor
Check search request -- add to -- Post Processors --json Extractor

2. Set up json Extractor

Explanation of various parameters :
1. Names of created variables: Express json The variables stored in the content obtained by the extractor from the response , Any definition, as long as there is no conflict , Suggest a meaningful name , Don't write as abc Meaningless names
2. JSON Path Expressions:json Extracted expression , Indicates that you need to match the content from the response according to this rule , The expression in the figure represents all... In the matching response name The value corresponding to the field
3. Match No. (0 for Random): The strategy of storing the matching results into variables , The default is to write nothing 0
- 0 Represents a random variable stored in , For example, we matched multiple name Value of field , Then one of them will be randomly The value assigned to Names of created variables The specified variable
- -1 Indicates that a numeric suffix is used to identify each matching result , For example, we matched multiple name Value of field , Then eventually each result will correspond to a variable , The variable name is name_1、name_2、name_3、name_4 ....
- X Indicates that the value of the first few matches is assigned to Names of created variables The specified variable , For example, write a 2, Then it will match the second 2 Of name The value of the field is assigned to name
- Compute concatenation var: Indicates that if multiple values are matched , You can store multiple values in one variable , A variable called Names of created variables The specified variable name plus _ALL, For example, in the current figure is name_ALL, Store multiple values in , Division
- Default Values: Said if json The expression did not match any value , So what is the default value of the variable
Four 、 The configuration database initiates a database request
With mysql Database, for example
1、 Configure database connection components
Required to configure the database jar package , download mysql-connector-java.5.1.46.jar, Can be directly in maven Download from , Download address <a href="https://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.46" h"="">https://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.46

After downloading, put jmeter In the catalog lib/ext Under the table of contents , And then restart jmeter
To configure jdbc Components , Select thread group -- add to -- The configuration element --JDBC Connection Configuration


The meaning of the core field
- Variable Name for created pool: Indicates the name of the connection configuration , This name will be used later jdbc Use... In request
- Dabase URL: Indicates the connection address of the database instance
- JDBC Driver class: Represents the connection driver class
- Username: Indicates the user name of the database instance
- Password: Indicates the password to connect to the database instance
2、 Database request , Please note that the request needs to be placed before the query interface request
Select thread group -- add to -- Sampler --JDBC Request


The meaning of the core field
- Variable Name of Pool declared in JDBC Connect Configuration: Indicates the name of the database configuration to be connected , Consistent with our configuration above
- Query: Fill in sql sentence , Here we are looking up the commodity table , adopt name Field fuzzy query , And only returned name Field
- Result variable name: Indicates which variable the content found in the database is stored in , Write the variable name here
5、 ... and 、 Script debugging
1. Add debug sampler , Used to check whether the value of each variable is correct
Select thread group -- add to -- Sampler -- Commissioning the samplers

2. Add view result tree , Used to view request results
Select thread group -- add to -- Monitor -- Look at the fruit tree

3. Perform the test , Check whether the value of each variable is correct

6、 ... and 、 Use Beanshell The assertion completes the verification of interface results and database results
Check search request -- add to -- Assertion --BeanShell Assertion


Execute the entire script , Carry out by , The full picture of the script is as follows

a key : Learning materials of course, learning is inseparable from materials , Of course, here is also prepared for you 600G Learning materials
Private keywords needed 【000】 Get it for free Note that the keywords are :000
Project practice
app project , Bank Project , Medical Project , Online retailers , Finance

Large scale e-commerce projects

Full set of software test automation test teaching video

300G Download tutorial materials 【 Video tutorial +PPT+ Project source code 】

A complete set of software testing automation testing factory has been

python automated testing ++ A complete set of templates + Performance testing


It's said that the iron juice who has paid attention to me for three consecutive years has been promoted, raised and made a fortune !!!!
边栏推荐
- MySQL - use field alias after where
- FSOs forest simulation optimization model learning notes
- Binary tree traversal - recursive and iterative templates
- Startup, connection and stop of MySQL service
- Introduction to common activation functions
- Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier
- How to turn on the hotspot for the mobile phone after the computer is connected to the network cable
- This of phaser3 add. add. image
- Exercise 5.14 input n strings, arrange them in alphabetical order and output them.
- leetcode743. 网络延迟时间(中等, dijkstra)
猜你喜欢

The storage structure of a tree can adopt the parent representation, that is, the parent pointer array representation. Try to give the corresponding class definition. Each tree node contains two membe
![[projet cs144 de Stanford Computing Network] lab1: Stream reassembler](/img/7b/fad18b68a6ee30d1dec4dad6273b98.png)
[projet cs144 de Stanford Computing Network] lab1: Stream reassembler

Network communication tcp/ip

Introduction to common activation functions

【MathType】利用MathType输出LaTex样式的公式

A problem discovery and attempted solution to the strange stop of server script

leetcode743. 网络延迟时间(中等, dijkstra)

【斯坦福計網CS144項目】Lab1: StreamReassembler

Lecture on Compilation Principles

Introduction to convolutional neural network
随机推荐
【斯坦福計網CS144項目】Lab1: StreamReassembler
Pytorch's leafnode understanding
[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx
Detailed explanation of Joseph problem
【官方文件汇总】国科大学位论文撰写规范
A summary of global variables and typedef
Transaction characteristics and isolation levels
Crypto JS reports uglifyjs error
Mysql database listening -canal
Note: common gadgets in project architecture
Reinstall opencv and step on the pit.
redis
Database query user mailbox
Three paradigms of database
ng-tv-focusable
This of phaser3 add. sprite
Wildcard usage of go standard library FMT
MySQL - use field alias after where
URI, URL and urn difference, relation and syntax diagram
Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier