Some time ago, I chose a special period of time to prepare for the interview. After two interviews, I have some profound understanding. For enterprise requirements, in addition to professional theoretical knowledge, the test tool is also valued.

A quick start using JMeter tests

1. What is a thread group

Process: A process corresponds to an executing program

Thread: A process has multiple threads of execution

Program group: Grouping of threads by their nature. View task Manager (iQiyi has multiple)

A process has multiple thread groups, and a thread group has multiple threads

Test Plan – Thread Group – Number of threads in the thread group property Concurrent execution: Multiple threads are executed at the same time. By default, threads in a thread group execute concurrently. Each thread executes HTTP requests within the group. Set thread group order: Select the thread group in the test plan (each thread group runs independently) to simulate concurrent access by users

Creating a thread Group

A thread group consists of three main parameters:

Number of threads, ramp-up Period(in seconds), and number of loops.

The number of threads:

Virtual number of users. A virtual user occupies a thread. Set the number of virtual users and in this case, set the number of threads.

Preparation time (seconds) :

How long does it take for the set number of virtual users to start up? If the number of threads is 20 and the preparation time is 10, then it takes 10 seconds to start 20 threads. That’s two threads per second.

Number of cycles:

Number of requests sent per thread. If the number of threads is 20 and the number of loops is 100, then each thread sends 100 requests. The total number of requests is 20*100=2000. If “forever” is checked, all threads will continue to send requests until they choose to stop running the script.

The scheduler

Set the start time and end time for the thread group to start. (When configuring the scheduler, check the number of cycles to forever.)

Duration (seconds)

The duration of the test, which overrides the end time

Start delay (s)

The test delays the startup time, overwriting the startup time

The startup time

Test startup time, which is overridden by startup delay. When the startup time has passed, the current time will override it when you manually test only.

The end of time

Test end time, duration will override it.

Creating an HTTP request

I’ve seen the most, so we’ll focus on:

Specify the request domain name and request path

Description of interface files

Set the content to be viewed

Note: If the listener starts with jp@gc, it is a third-party plug-in

Sample: indicates the sequence number of each request. Start Time: indicates the Start Time of each request. Thread Name: indicates the Name of each Thread. Request status. A check mark indicates success, and a cross mark indicates failure. Bytes: the number of Bytes requested. Sample number: the number of successful requests, which is equal to the number of concurrent requests you set times the number of loops. Average: Average time per thread requested. Changes in server response time, the size of the dispersion measure, or, in other words, the distribution of the data.

Viewing the result tree

  • Request data display (request header, request parameters,,)

  • Data display of the response (response code, response header,,)

By looking at the result tree, we can see the result of each request, where red is the request that failed and green is the request that passed.

Thread Name: indicates the Thread group Name

Sample Start: indicates the Start time

Load Time: Load duration

Latency: Latency

Size in bytes: indicates the total Size of data to be sent

Headers Size in bytes: indicates the size of the rest of the sent data

Sample Count: Send statistics

Error Count: indicates the statistics of interactive errors

Response code: Return code

Response message: Return message

Response headers: Indicates the returned header

Aggregation report parameters

Lable: for each HTTP request, the Name of the HTTP request is displayed. For example, the Name of a Baidu HTTP request is Baidu
#Samples: indicates how many requests were made during this test, as shown above, the Sougou and Baidu HTTP requests each made 30 requests
Business: the Average response time, refers to all the requests of the Average response time, above 30 requests of the total response time is divided by 30 to come up with the Average response time, the default is a single request under the Average response time, but when using the controller “affairs”, shows that the Average response time for the unit with the things
Median: Median response time of 50% of users
90%Line: 90% user response time
Min: indicates the minimum response time
Max: indicates the maximum response time
Error% : The number of incorrect requests/the total number of requests in this test. As shown in the figure above, in this test, 66.6% of Sougou’s HTTP requests were incorrect, while none of Baidu’s requests were incorrect
Throughput: Indicates the number of requests completed per second by default. As shown in the preceding figure, the number of requests completed per second is 6.6 and 6.2 respectively
Received KB/Sec: Indicates the amount of data received from the server per second. The unit is KB

Master: average time, error rate, throughput.

Graphic results

Function: Display the distribution of the performance test data through graphs. The graphical results are generally used as an analytical aid to aggregate reports

Sample number: Total number of requests sent to the server.

Latest sample: a number representing the time when the server responded to the last request.

Throughput: The number of requests processed per minute by the server.

Average: Total run time divided by the number of requests sent to the server.

Median: Half the server response times were below this value and half were above this value.

Deviation: Indicates the size of the measured value of the server response time change and the degree of dispersion.

Introduction of JMeter main components

The test plan

1. The test plan is a complete scenario

2. “Run each thread group independently” : After this option is selected, all thread groups are executed sequentially. This option is generally deselected to allow all thread groups to start concurrently.

3. Function Test mode: After this parameter is selected, detailed request records are generated, which consumes resources and affects client performance. Generally, it is not selected.

4. User-defined variables: Global variables can be added to the test plan. Generally, you can add some common system configurations. If you want to switch the environment and configuration during the test, it is generally not recommended to add variables to the test plan

Thread group

(1) Thread group

This is the thread we normally add to run. Colloquially speaking, a thread group can be seen as a virtual user group, each thread in the thread group can be understood as a virtual user.

(2) Setup thread group

A special type of ThreadGroup that can be used to perform a pretest operation. These threads behave exactly like a normal thread group component. The difference is that these types of threads perform periodic thread group execution before performing tests; Similar to LoadRunner’s init, initialization is performed at the beginning of the test.

(3) TearDown thread group

A special type of ThreadGroup that can be used to perform post-test actions. These threads behave exactly like a normal thread group component. The difference is that these types of threads execute periodic thread groups after the end of the test; End, similar to LoadRunnner, is reclaimed at the end of the test.

Sampler (Http request)

The HTTP request attributes are described as follows:

1) Name: Used to identify a sample. It is recommended to use a meaningful name

2) Comment: it has no effect on the test and is only used to record user-readable comment information

3) Server name or IP address: The name or IP address of the target server to which the HTTP request is sent, such as www.baidu.com

4) Port number: Specifies the port number of the target server. The default value is 80

5) Protocol: The protocol for sending HTTP requests to the target server, HTTP/HTTPS, case insensitive, default HTTP

6) Method: send HTTP request method (link: www.Tester. Com //p/5630940….

7) Content encoding: Content encoding (content-type =application/json; Charset = utf-8)

8) Path: The destination URL path (excluding the server address and port)

9) Automatic redirection: If this item is selected, the response to the HTTP request is 301/302, and jMeter will redirect to the new interface

10) Use keep Alive: HTTP communication between jmeter and target server using keep-alive mode (default)

11) Use multipart/from-data for HTTP POST: Used when sending HTTP POST requests

12) Parameters, Body Data, and Files Upload

  1. Parameter refers to the parameters in the function definition, while argument refers to the actual parameters in the function call

  2. Parameter = formal parameter, argument= actual parameter

3. If you are not strict with the argument, you can use the argument. While parameter uses less While defining method, variables passed in the method are called parameters. When defining a method, the variables passed into the method are called parameters. While using those methods, values passed to those variables are called arguments. When a method is called, the value passed to the variable is called an argument.

4. Body Data refers to the entity Data. It is the content of the Body entity in the request packet

When selected, make an HTTP request and receive the HTML file content in response. Parse the HTML and retrieve all the resources (images, flash, etc.) contained in the HTML: (Not selected by default) If the user only wants to obtain a specific resource, you can fill in the Embedded URLs Must Match text box below with the specific resource expression to download. Only URLs that match the specified regular expression will be downloaded

The listener

The Listener is responsible for collecting test results and is also told how the results will be displayed. Common examples include aggregating reports, viewing result trees, and viewing results in tables, all of which support writing result data to a file. Just add the rest and see. Aggregation reports were covered earlier, followed by screenshots of viewing the result tree and viewing the results in a table.

Transaction controller

What it does: The transaction controller produces an additional sampler that counts all The Times of the controller’s children.

Create a transaction controller under the thread group

Parameters:

  • Generate parent sample: Generate parent sample: Generate parent sample
  • Include duration of timer and pre-post processors in generated sample: If this item is selected, the time of the timer is counted. Otherwise, only the time of the sample is counted

Create the sample to access the home page and the registration page

Generate aggregation reports

Check the

There is only one transaction report in the aggregate report

Assertion — checkpoint

Assertions can be used to determine whether the result of a request response is what the user expects. It can be used to isolate the problem domain, that is, to perform stress tests while ensuring proper functionality. This limitation is very useful for effective testing.

Two important assertions: response assertions and JSONAssertion

Response assertion:

JSON assertion:

Front processor and rear processor

Pre Processors and Post Processors are responsible for doing the work before and after the request is generated. The pre-processor is often used to modify the Settings of the request, and the post-processor is often used to process the data in response. We mainly use the postprocessor’s regular expression extractor for dynamic correlation.

The timer

The Timer defines the delay interval between requests

3. Parameterize JMeter components

1. CSV Data Set Config:CSV Data control

Application scenario: When the parameter range is large, users can easily modify the parameter data at any time. The most commonly used is the parameterized user name and password login system.

steps

Create a text document in the specified path and fill in multiple contents

2, through theAssistant function

Usage scenario: JMeter built-in function processing, such as: random number, can be used for fixed characters + random number, to modify the value of the passed parameter, function helper underlying are Java encapsulated methods.

steps

1. Click Options – > Function Assistant to call up the function Assistant dialog box

Select the _CSVRead function (the first box in the figure below).

1) The first parameter: enter the file path.

2) The second parameter: the column number of the file starts from 0, the first column is 0, the second column is 1, the third column is 2, and so on. Then click the “Generate” button, and the parameterized function we need will be generated automatically. 3) Copy the generated parameterized function, where the copy process needs to use. 4) _Random function reads data randomly from a data segment to replace parameters. It is used when multiple data records need to be added and some fields need to be unique.

3,User-defined variables

Application scenario: This parameter can be used to set parameters that do not change frequently in the test plan, such as host, port number, and URL. And the user-defined variables are in the configuration component.

steps

(1) Add user-defined variable function module

(2) Configure user-defined variable parameter values

The following uses different server addresses and ports as an example:

(3) Configure parameter values in the HTTP request or parameterized fields in the message body data

When the address of the sending request server changes, you only need to change the server parameterization value to send the request to different servers. Of course, user-defined variables can also be used to parameterize login user, transaction amount, account and other scenarios.

Extract JMeter regular expression

Using the Jmeter regular extractor, you can get the required content from the response result of the request, thus achieving correlation. Association refers to the data that needs to be obtained from the previous request and sent back to the next request because there is a data dependency relationship between requests. Regular expression describes a pattern of string matching. It can be used to check whether a string contains a substring, replace a matching substring, or take a substring from a string that meets a condition, etc.

You construct regular expressions the same way you create mathematical expressions. That is, multiple metacharacters and operators can be used to combine smaller expressions to create larger ones. The components of a regular expression can be a single character, a set of characters, a range of characters, a choice between characters, or any combination of all of these components.

Settings related to regular expression extraction

​ 

Description:

(1) Reference name: the name of the parameter to be referenced in the next request. For example, if title is entered, ${title} can be used to reference it.

(2) Regular expression: () : The part in brackets is what to extract. . : Matches any string. + : one or more times. ? : Don’t get greedy and stop after the first match.

(3) Template: use $$reference, if there are more than one regular expression in the regular expression, then can be $2$$3$, etc., indicating the parse to the value of the title. For example, 111 indicates the first value resolved

(4) Matching numbers: 0 indicates the random value, 1 indicates all values, and usually 0 is entered

(5) Default value: If the parameter does not get a value, it is given a value by default.

Example: API interface

digression

If you are interested in this part of the content, you can continue to pay attention to the account of the small series, in addition, also recorded a lot of technical videos in this respect, if necessary, you can private ❤️ author to obtain oh!