Detailed explanation of pressure measurement using Jmeter

Introduction: 1. An overview of a tool often has many functions and many details. In actual testing work, most scenarios will use some core functions, and we do not need to go into details at all. Master all the features of the tool. Therefore, this article will use the least expensive way to explain how to quickly get started using jmeter for stress testing. JMeter, an interface testing tool, is a Java program and requires a JDK environment. It is recommended to use JDK8 or JDK11.

1 Overview

A tool often has many functions and many details. In actual testing work, most scenarios will use some core functions. We do not need to master all the functions of the tool in detail. . Therefore, this article will use the least expensive way to explain how to quickly get started using jmeter for stress testing.

JMeter, an interface testing tool, is a Java program and requires a JDK environment. It is recommended to use JDK8 or JDK11.

download link:

Apache JMeter - Download Apache JMeter

start up:

Installation path/bin/jmeter.bat (.sh)

At the same time, I have also prepared a software testing video tutorial for everyone (including interviews, interfaces, automation, performance testing, etc.), which is below. If you need it, you can watch it directly, or you can directly click on the small card at the end of the article to get the information document for free.

Where to watch software testing video tutorials:

Byte boss teaches you how to master automated testing (interface automation/APP automation/Web automation/performance testing) within 15 days, including practical project practice

2. Test plan, thread group, sampler

test plan:

Test plan, a test plan in jmeter corresponds to a test scenario.

thread group:

Thread group, a thread group in jmeter corresponds to a behavior. A behavior can be understood as a scenario, which can be composed of multiple interfaces. For example, placing an order can include multiple interfaces such as inventory deduction and order generation.

Sampler:

It can be understood as a request. Jmeter supports multiple types of samplers. Of course, the one we commonly use is the http sampler.

The relationship between the three:

The entire use of jmeter is actually to create a test plan, and then add various needed things to this test plan, such as thread groups, listeners, etc.

A thread group contains multiple samplers, and a sampler is a request. Each thread in the thread group will execute the samplers in the group completely from top to bottom.

Create a test plan and add a thread group:

Add a sampler to the thread group, and add the http sampler to the request for the http interface:

After a complete set of test plans is built, it can be exported to a file. After exporting to a file, you can run the entire test plan through commands without leaving the interface:

3. Debugging and running

If the test plan is executed directly, no results will be displayed. You need to add a listener for debugging and viewing intermediate results.

Generally, view results tree is used to view the listener of the results tree, and the running results can be viewed.

 The meaning of some core parameters:

Connect Time: The time to establish a TCP connection.

Lantency: The time between sending a request and receiving the first response.

Loadtime: The time from before the request is issued to when all responses are received.

Size in bytes: The size of the entire response message = header+body.

Headers size in bytes: response header size.

Body size in bytes: The body size of the response.

4. Request default value

Request defaults, which are the requested default configuration defaults. After configuring, all requests in a test plan will use the configuration in the request default value by default.

5. Traffic recording

When testing a web page, in addition to the API, the http request also contains many requests for static resources (html/js/css). How many URLs are sent to request this page? You can use jmeter's traffic recording function to record all http requests in a certain visit. This function is rarely used in actual stress testing. Here I just mention that this function exists without expanding it. When you need to use it specifically, you can search for it and how to use it.

6. Simulation time interval

You can use a timer to simulate time intervals. The timer's scope is all sibling nodes and its child nodes under the node where it is located.

There are many kinds of timers. Some timers do not have fixed time intervals, such as Gaussian timers whose time intervals satisfy Gaussian changes. You can search for specific types.

7. Stress test

Run command:

The real stress test does not use the graphical interface for testing, because the graphical interface will also have performance losses as an intermediate layer, but directly uses the command line mode.

{base dir}\bin\jmeter -n -t XXX.jmx -l log.jtl

XXX.jmx is a jmx file exported after being configured using the graphical interface.

Stress testing generally gives test cases to describe performance requirements. The following is a performance test case:

Users do not need to log in. They first visit the home page, then the single course page, and finally the news page.

The interval between accessing pages is 10 seconds.

The number of users is 1,200, and they come online in 10 minutes.

Just configure jmeter according to the test case. The above requirement description is converted into jmeter configuration:

Create a thread group with 1,200 threads and execute it within 10 minutes;

There are three http samplers under the thread group. In order, they request the homepage, request the single lesson page, and request the news page;

Create a timer to sample every 10 seconds.

8. Report

jmeter can generate HTML reports

jmeter -n -t [Jmx script location] -l [Intermediate file result.jtl location] -e -o [Report specified folder]

An HTML file will be generated in the report folder, which will contain detailed statistics on all URL requests, including success, failure, time-consuming and other information.

Here is an example:

A little help

PS: Here is a collection of self-study tutorials for software testing. It should be very helpful for those who are developing in the testing industry. In addition to basic introductory resources, bloggers also collect a lot of advanced automation resources. From theory to practice, only by integrating knowledge and action can you truly master it. The full set of content has been packaged on the network disk, and the total content is close to 500 G.

☑ 240 episodes - a complete set of video courses from zero to mastery
☑ [Courseware + Source Code] - complete supporting tutorials
☑ 18 sets - source code of practical testing projects
☑ 37 sets - testing tool software package
☑ 268 - real interview questions
☑ 200 templates - Interview resume template, test plan template, software test report template, test analysis template, test plan template, performance test report, performance test report, performance test script case template (complete information)

These materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you! Everything must be done early, especially in the technical industry, where technical skills must be improved.

Guess you like

Origin blog.csdn.net/huace3852/article/details/132919941