Jmeter series-detailed introduction to test plan (3)

The role of test planning

  • The test plan describes a series of steps when Jmeter is executed
  • A complete test plan contains one or more [thread groups, logic controllers, samplers, listeners, timers, assertions and configuration elements]

Introduction to Jmeter original parts and components

Introduction to basic components

Container for multiple similar functional components (similar to classes)

image-20230217175228157

Basic introduction to components

Implement an independent function (similar to a method )
image-20230217175404855
Insert image description here

Configuring elements in the tree

  • Each control in the tree can be displayed through the content area on the right
  • Every control in the tree can be dragged anywhere in the tree

Run test plan

  • You can run the test plan via ctrl+r

Pause running test plan

Insert image description here
Two ways to pause

  • Stop thread (ctrl + .) [hard interrupt]
  • Close the thread (ctrl + ,) [soft interrupt]

stop threads

  • Many samplers are interruptible, meaning that active sampling can be terminated early
  • The stop command will check if all threads have been stopped within the default timeout (i.e. 5000 ms = 5 seconds)
  • If there is a thread that has not been stopped, a message will be sent; at this time, you can send the stop command again, but if it still fails, you have to exit Jmeter to clean up.

Note that
the default timeout mentioned above can be changed through the Jmeter property jmeterengine.threadstop.wait [jmeter installation directory/bin/jmeter.properties]
Insert image description here

shutdown threads

  • The thread will stop after the currently running task ends and will not interrupt the tasks being executed by the active thread.
  • A [Stop Testing] window will appear (as shown below) and will not be closed until all threads have finished running.
  • If the stop time is too long, you can also directly issue the stop command.

How to stop thread execution in CLI mode

In the bin directory, run the script

  • stoptest.cmd / stoptest.sh [hard interrupt]
  • shutdown.cmd / shutdown.sh [Soft interrupt]
    Note that Jmeter will only accept scripts running under the same host.

Commonly used introduction

thread group

An ordinary and commonly used thread group can be regarded as a virtual user group. Each thread in the thread group can be understood as a virtual user.

  • setUp thread group: A special type of thread group that can be used to perform pretest operations

  • tearDown thread group: a special type of thread group that can be used to perform post-test workimage-20230217221157866

HTTP request

Send http and https requests to the server
image-20230218093101549

View results tree

image-20230218105159603

Jmeter parameterization (emphasis)

1. User-defined variables

① Function: Define global variables;
Location: Test plan > Thread group > Configuration components > User-defined variables
② Define globally used variables, such as protocols, domain names, ports, etc.: ③
Insert image description here
Reference the defined variable names in HTTP requests, format: ${ Variable name}
Insert image description here
④View the result tree
Insert image description here

2. User parameters

①Function: For the same set of parameters, when different users come to access, different values ​​can be obtained, but different values ​​cannot be obtained for different loops of the same user; Location: Test Plan》Thread Group》Preprocessor
》 User parameters
② Add user parameters: ③
Insert image description here
Reference the defined variable name in the HTTP request, format: ${variable name}

Insert image description here

④ View the result tree
Insert image description here

3. CSV data file

① Function: Allow different users to obtain different values ​​during multiple loops;
Location: Test Plan》Thread Group》Configuration Component》CSV Data File Settings
② Define csv data file:
Insert image description here
③ Parameter introduction:
Insert image description here
Insert image description here

④ Reference the defined variable name in the HTTP request, format: ${variable name}
Insert image description here
⑤ View the result tree
Insert image description here
Note: The number of loops is set on the thread group page
Insert image description here

4. Function (__counter)

① Function: Counting function, generally used for counting execution times. No need to prepare data in advance. Automatically add counts to complete parameterization;
location: Select "Tools" in the menu
to set the function assistant dialog box :

  • TRUE, each user has its own counter; FALSE, use the global counter
  • Name of variable in which to store the result(optional):Variable name used to store the result(optional)

In the HTTP sampler, the value generated by the counter function can be read by applying the function string generated by the counter function. if counter

  • The parameter is set to: TRUE, then each user is counted separately (counted separately) starting from 1, and 1 is added each time in the loop. If counter

  • If the parameter is set to: FALSE, then all users will have a common (global count) counter. Every time a request is sent, the value will be incremented by 1.
    ② Parameter introduction:
    Ⅰ. ${__Random(,)}: The first parameter of the method is a random number The lower limit
    of Columns in the file (the number of columns starts from 0);
    Ⅲ. KaTeX parse error: Expected group after '_' at position 2: {_̲_StringFromFile… {__StringFromFile(,)} method does not specify which column in the file to read. , so KaTeX parse error: Expected group after '_' at position 2: {_̲_StringFromFile... {__counter}: No need to prepare data, jmeter automatically adds counting to complete parameterization (TRUE:, each user counts separately; FALSE: All users use global count)

The following is an example of using ${__Random(,)}:
③ Open the function assistant, select Random, and set the function parameters:
Insert image description here
④ Copy the function generated by the function assistant into the parameters of the HTTP request.
Insert image description here
⑤View the result tree
Insert image description here

Guess you like

Origin blog.csdn.net/m0_62091240/article/details/132746714