Detailed explanation of different ways of realizing parameterization of Jmeter

Introduction to Parameterization

Definition : Dynamically acquire, set or generate data, which is a program-driven instead of manual-driven data design scheme, improving script writing efficiency and writing quality Applicable scenario: When the amount of
submitted data is large, it is too troublesome to modify each time , you can use parameterization
This article introduces 4 ways to achieve parameterization :
1. User-defined variables
2. CSV data file settings
3. User parameters
4. Functions

1. User-defined variables

Note : This form can be defined as [user-defined variable] when a segment of address appears repeatedly, so that it can be called at any time later.
Parameterization method:
1. Create a new user-defined variable by right-clicking [Test Plan-Add-Configuration Component-User-Defined Variable]
2. Add [Variable Name] and [Variable Value]
Variable name: custom; Variable value: call interface The part that needs to be parameterized
insert image description here
3. Modify the corresponding variable name in the path of the http request of the interface, and the calling method is as follows:

${
    
    变量名}

insert image description here

2. CSV data file settings

Note : Realize the separation of data and scripts. This form is widely used in daily use scenarios to
achieve parameterization:
1. Create a CSV file to store test data; CSV: comma separator, is a concise and common data storage format, when saving Encoding format: [utf-8].
2. Right-click [Test Plan-Add-Configuration Component-csv Data File Settings]
3. [CSV Data File Settings] Precautions, as shown in the following figure
insert image description here
4. To execute the thread group of the CSV data file, [Cycle Number] should be changed to: Forever, so that the system can dynamically execute all test data.
insert image description here
5. Set the parameters of the corresponding interface in the thread to the form of dynamic parameters, as follows

${
    
    参数名}

3. User parameters

Note : This form of script and data dependence is relatively strong, and it is not widely used in daily use scenarios. Realize
parameterization methods:
1. Create new user parameters: right-click [Thread/Interface Request-Add-Preprocessor-User Parameters]
insert image description here
2. [User Parameters] setting, as shown in the following figure
insert image description here
3. Set the [Thread Number] in the corresponding [Thread Group] = the number of users in [User Parameters]
insert image description here
4. Set the parameters of the corresponding interface in the thread to the form of dynamic parameters, as follows

${
    
    参数名}   (参数名和【用户参数】中设置的变量保持一致即可)

4. Function

Thread group settings, as shown below:
insert image description here

1. Counter function: _counter

1.1.TURE: Each user has its own counter

${
    
    __counter(TURE,)}

Click [Function Assistant] in the menu bar to select counter, variable value=true, click Generate Function, copy the generated string, and place it after the request name. The execution result will dynamically generate a digital value after the request name (each user has his own Counter)
insert image description here
insert image description here
execution results, as shown in the figure below:
insert image description here

1.2.FALSE: All users share a counter

${
    
    __counter(FALSE,)}

Other settings are the same as TRUE, and the execution results are as follows:
insert image description here

2. Random function: _Random

2.1. Parameter 1: The minimum value of the value range (included)

2.2. Parameter 2: The maximum value of the value range (included)

insert image description here

${
    
    __Random(1,3,)}

The execution result is as shown in the figure below: 2 users each cycle 3 times, each time randomly assigning 1, 2, 3,
insert image description here

3. Get the current time function: _time

3.1. No parameter: get the millisecond value from 1970/01/01 00:00:00

insert image description here

${
    
    __time(,)}

Execution results, as shown in the figure below: Timestamps are generated later
insert image description here

3.2. Parameter 1: [yyy_MM_dd HH:mm:ss] formatted as [year_month_day hour:minute:second] format

insert image description here

${
    
    __time(yyy_MM_dd HH:mm:ss,)

The execution result is shown in the figure below:

Guess you like

Origin blog.csdn.net/weixin_37600187/article/details/128955871