Use JMeter test web application

xiaoxiao2021-03-05  24

Use JMeter test web application

In the next chapter, the author will detailed how to use JMeter to test the complete process of the web application.

2.1 test environment

The author uses Tomcat as a web server to test, the content being tested is a JSP file and a servlet, JSP file call javabean, print information, servlet accepts user parameters, call JavaBean, and outputs information. For details, please refer to the author's content provided by the author.

2.2 Installation Start JMeter

Everyone can download the RELEASE version of Jmeter by http://apache.linuxforum.net/dist/jakarta/jmeter/binaries/jakarta-jmeter-1.9.1.zip, and then extract the downloaded .zip file to C: / JMeter (% JMeter% will be used in later articles to reference this directory) directory. Now, use the JMeter.bat batch file below the% JMeter% / bin to start the JMeter's visualization interface, the following work will be operated on this visual interface interface. The following picture is a screenshot of the JMeter's visual interface.

Figure 1: Screenshot of the JMeter opens

2.3 Establishing a test plan (Test Plan)

The test plan describes the execution procedure and step of the JMeter during the test, and a complete test plan includes one or more thread groups, logic controllers, instance generating controllers, detecting Listener, Timer, ASSERTIONS, Config Elements. When you open JMeter, it has established a default test plan, and an instance of a JMeter application can only establish or open a test plan. Now let's start populating a test plan, this test plan issues a request to a JSP file and a servlet, we need JMeter to simulate five requestors (that is, five threads), each requester is requested twice, below The chapter introduces the detailed steps.

2.4 Adding load information settings

This step, we will add relevant load settings to the test plan, and JMeter knows that we need to simulate five requesters, each requiring, continuously request twice during the test. The detailed steps are as follows:

1. Select the Test PLAN node on the left tree in the visual interface, right click, select Add'thread Group, and his setting information box will appear on the right side of the interface.

2. Thread Group has three parameters related to load information:

Number of threads: Set the number of users who send requests

RAMP-UP Period: The total time interval that occurs every request, unit is second. For example, your request is 5, and this parameter is 10, then the interval between each request is 10/5, that is, 2 seconds.

LOOP Count: Requests the number of repetitions, if you choose the later Forever (default), the request will continue, if you do not select Forever, enter the number in the input box, then request to repeat the specified number, if you enter 0, then The request will be executed once.

According to our design, we should set Number of Threads to 5. Ramp-up Period is set to 0 (which is also concurrent requests), do not select ForeVer, enter 2 in the input box behind loop count, after setting Screenshots are as follows: Figure 2: Set the Thread Group for the parameters.

2.5 Add the default HTTP property (optional)

The actual test work is often expanded to the web application on the same server, so JMeter provides settings, and the same parameters can be ignored in the following HTTP request settings in the default HTTP property settings. Settings, reduce the time of setting parameters entry. This property will be adopted here. You can set the default HTTP attribute by the following steps:

1. Select the Test PLAN node on the left tree on the visual interface, right click, select Add'Config Element'HTTP Request Defaults, and his setup information box will appear on the right side.

2. The main parameters of the default HTTP property are as follows:

Protocal: A protocol used when sending a test request

Server Name or IP: IP address or name of the test server

PATH: The default start position. For example, set the PATH to / JMeter, then all the / JMeter path will be added in all HTTP requests.

Port Number: Port number for servers

Our test plan will test the web application on this web server, so protocal should be http, IP use localhost, because the Context path released by this web application is / JMeter, so the PATH set to / Jmeter, because With Tomcat servers, Port Number is 8080. The screenshot of the settings is as follows:

Figure 3: Default HTTP parameters used in test plans

2.6 Add HTTP request

Now we need to increase HTTP request, and he is also part of the content of the content we test. You can add sexual HTTP requests by the following steps:

1. Select the Thread Group node on the left tree in the visual interface, right click, select Add'sample'Http Request, and his setup information box will appear on the right side.

2. His parameters and the HTTP properties described in 2.5 are similar. In the increased properties, there is a selection of methods when sending HTTP, and you can choose to get or post.

We now add two HTTP requests because we set the default HTTP attribute, so the same properties in the default HTTP property are no longer repeated. The screenshot of the settings is as follows:

Figure 4: Set good JSP test request

Figure 5: Set good servlet test request (with parameters)

2.7 Increasing Listener

Increasing Listener is to record test information and can use the visual interface provided by JMeter to view test results, there are several result analysis methods to choose from, you can choose different results display mode according to your own habits, we use forms here The form is to view and analyze test results. You can add Listener by the following steps:

1. Select the Test PLAN node on the left tree in the visual interface, right click, select Add'Listener'View Result In Table, and his setting information and results display will appear on the right side of the interface.

2. You can set the filename property settings above the interface to save the test results to a file. Next, you will use the table to display the test results, the first column of the table, the order and number of the Sampleno display request execution, and the URL displays the goal of the request sent. The Sample-MS column shows this request to complete the time, and the last SUCCESS column shows whether the request is successfully executed. The bottom of the interface You can also see some statistics, the most concerned should be Average, that is, the average time. 2.8 Start the test plan

Now you can start the test plan by clicking on the menu bar Run -> Start. Below, the two pictures are the first time, the results of the second implementation of the test plan:

Figure 6: The result of the first execution shows

Figure 7: The result of the second execution shows

Everyone can see that the first execution is from JSP Request, which can be interpreted by the following reasons: JSP execution needs to be compiled into a .class file. So the second result is the normal result.

3 summary

JMeter is used to provide power or performance testing, and we can visualize test programs by using JMeter, including what kind of load, test, incoming parameters, while he provides a variety of The graphical test results are displayed, so that we can simply start testing work and analyze test results.

In this article, according to our own experience, the author demonstrates how to use JMeter to perform Web test, simply introduce the meaning of the relevant parameters in the graphical display interface of the test results. I hope to help you learn the basic knowledge of JMeter, and you can refer to this process and JMeter's help documentation to implement a test process of Java objects, databases, etc.

Reference:

JMeter's User Guide:

http://jakarta.apache.org/jmeter/Usermanual/index.html

Tool download:

Tomcat

http://jakarta.apache.org/tomcat/index.html

2. Jmeter

http://jakarta.apache.org/jmeter/index.html

转载请注明原文地址:https://www.9cbs.com/read-37363.html

New Post(0)