Summary of common Jmeter parameterization methods

Table of contents

      Foreword:

  parametric concept

  Parameterized way

  2. User variables

  3. CSV data file

  4. Function Assistant


      Foreword:

         When performing interface performance testing, we usually need to perform parameterized operations for different scenarios. JMeter is a powerful performance testing tool that provides a variety of parameterization methods to facilitate testers to construct test cases.

  parametric concept

  In testing work, different data sending requests are usually used to test different scenarios to achieve the comprehensiveness of the test, which requires parameterization of some fields so that each iteration uses different data to meet our testing needs.

  As one of the commonly used function and performance testing tools, Jmeter’s parameterization method is also relatively flexible. It is mainly divided into four types: user parameters, user-defined variables, CSV data files, and function assistants. These four types will be introduced in detail below How to use parameterized methods.

  Parameterized way

  1. User parameters

  1. Usage scenarios

  It is suitable for scenarios where the value range of parameters is small, such as testing and simulating that few users log in to a certain system for transactions.

  2. Operation steps

  (1) Add user parameter function module

  (2) Set parameter variables and user values

  Pay attention to check the update for each iteration, otherwise the same data will be used every time;

  (3) Configure parameter values ​​in HTTP requests or parameterized fields in message body data

  In the HTTP request, the request is sent either by setting parameters or by using message body data in a message. Either way, the parameterized value should be consistent with the variable name in the user parameter.

  (4) View the result tree

  Set the number of threads in the thread group to 2, click Execute, and you can view the parameter usage by viewing the result tree:

  2. User variables

  1. Usage scenarios

  It is generally used for parameter settings in the Test Plan that do not need to iteratively change with the request, such as server address and port.

  2. Operation steps

  (1) Add user-defined variable function module

  (2) Configure user-defined variable parameter values

  Here is an example of configuring different server addresses and ports:

  (3) Configure parameter values ​​in HTTP requests or parameterized fields in message body data

  When the address of the sending request server changes, you only need to change the parameterized value of the server to send requests to different servers. Of course, user-defined variables can also be used to parameterize scenarios such as login users, transaction amounts, and accounts.

  (4) View the result tree

  When the server name is set to ${host1} and the port is set to ${post1}, access to Baidu server:

  When the server name is set to ${host2} and the port is set to ${post2}, access the Firefox server:

  3. CSV data file

  1. Usage scenarios

  It is suitable for scenarios with a large range of parameter values. This method has high flexibility and convenient operation when parameterizing a large amount of data. It is often used when it is necessary to traverse thousands of account scenarios.

  2. Operation steps

  (1) Prepare parameterization files

  The parameterization file is generally in txt or csv format. Each row represents a piece of data. Each piece of data can contain multiple attributes. Different attributes need to be separated by separators. CSV data files have no requirements for the amount of data. When the number of parameterization is required When the amount is large, this parameterization method should be used:

  (2) Add CSV data file setting function module

  (3) Configure CSV data file parameters

 The file parameter configuration details are as follows:

 instruction manual:

  The relationship between recirculating when encountering the end of file and stopping the thread when encountering the end of file:

  When the end-of-file character is encountered and the loop item is true again, it is meaningless to stop the thread item when the end-of-file character is encountered, because the previous item controls to keep reading in a loop;

  When the end-of-file character is encountered and the cycle item is false, when the end-of-file character stop thread item is true, when the number of threads is 4 and the parameter value is 3, the request will be executed 3 times;

  When the end-of-file character is encountered and the cycle item is false, when the end-of-file character stop thread item is false, when the number of threads is 4 and the parameter value is 3, the request will be executed 4 times, but the last request will report an error , because the fourth request has no parameters;

  (4) Configure parameter values ​​in HTTP requests or parameterized fields in message body data

  (5) View the result tree

  The number of threads in the thread group is set to 3, and the number of cycles is set to 1. You can see that the parameter values ​​​​in the execution result are consistent with the data in the CSV file:

  4. Function Assistant

  1. Usage scenarios

  When the parameter is a random number or the message contains a serial number field (which cannot be repeated in each iteration), the function assistant can be used to generate the required data. When the required field data is long and cannot be repeated, the time function is usually combined with the The counters are combined and spliced ​​into valid data of appropriate length.

  Jmeter provides a wealth of built-in functions, which can be roughly divided into the following seven types. Here, the combination of time functions and counters is used as an example to introduce the usage steps in detail.

  2. Operation steps

  (1) Configure the function as needed

  After opening the Function Assistant dialog box, select the time function, and then enter the desired time format, such as yyyyMMddHHmmss or MMddHHmmss, and click Generate to generate a referenceable parameterized function:

  (2) Configure user-defined variables

  Typically the generated referenceable parameterized function is set as the value of a user-defined variable:

  (3) Add counter function module

  (4) Configure the parameters of the counter module

  If we need a serial number with a length of 20 digits and cannot be repeated, then we can use the time function to generate a 16-digit value, use a counter to generate a 6-digit sequence value, and splice the two together to generate a 20-digit serial number And not duplicate data:

  (5) Configure parameter values ​​in HTTP requests or parameterized fields in message body data

  Combine the time function and the counter into a resqno variable, so that the resqno variable will not be repeated even if it is multi-concurrent:

  (6) View the result tree

  The above are the 4 parameterization methods commonly used by Jmeter. I hope to provide some help to my friends in the daily testing work!

 As someone who has been here, I also hope that you will avoid some detours. Here I will share with you some necessities on the way forward for automated testing, hoping to help you. (WEB automated testing, app automated testing, interface automated testing, continuous integration, automated test development, big factory interview questions, resume templates, etc.), I believe it can make you better progress!

Just leave [Automated Test]

Guess you like

Origin blog.csdn.net/Free355/article/details/131327075