Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to test the jmeter interface

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to test the jmeter interface". In the daily operation, I believe that many people have doubts about how to test the jmeter interface. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to test the jmeter interface". Next, please follow the editor to study!

A brief introduction to Jmeter

Jmeter is a pure Java open source project developed by Apache, which can be used for interface testing and performance testing.

Jmeter has high portability and can run across platforms.

Jmeter can implement distributed load.

Jmeter uses multithreading, allowing simultaneous sampling of different functions through multiple threads or through independent threads.

Jmeter has high scalability.

II. Jmeter installation

1. To install JDK, you must have JDK1.7 or above. Version 1.8 is recommended.

2. Go to the official website: http://jmeter.apache.org/download_jmeter.cgi downloads the latest Jmeter version, and decompress it to a non-Chinese directory, such as: d:\

3. Configure the environment variables of Jmeter.

(1) New variable: JMETER_HOME:D:\ apache-jmeter-5.2.1

(2) add the following variable to the front of the CLASSPATH variable:% JMETER_HOME%\ lib\ ext\ ApacheJMeter_core.jar;%JMETER_HOME%\ lib\ jorphan.jar

(3) add the following variable to the front of the PATH variable:% JMETER_HOME%\ bin

4. Enter D:\ apache-jmeter-5.2.1\ bin, double-click jmeter.bat, or enter the jmeter command in the dos window to open the jmeter interface. The installation is successful.

Set the Jmeter language to the Chinese environment

1. Temporary settings

Jmeter menu bar Select options choose Language à Chinese (Simplified)

In this way, after restarting the software, it becomes an English environment.

2. Permanent setting

Go to the apache-jmeter-5.2.1\ bin directory, find the "jmeter.properties" file, add "language=zh_CN" after line 37 of the file, save it, and then open jmeter to become a permanent Chinese environment.

IV. Main components of Jmeter

1. Test plan: the starting point for testing with JMeter, which is the container for other JMeter test components

2. Thread group: represents a certain number of users, which can be used to simulate users to send requests concurrently. The actual request content is defined in Sampler and is contained by the thread group.

3. Configuration components: maintain the configuration information needed by Sampler, and modify the content of the request according to the actual needs.

4. Pre-processor: responsible for working before the request, often used to modify the settings of the request

5. Timer: responsible for defining the delay interval between requests.

6. Sampler: the smallest unit that sends a request to the server and records the response information and response time in the performance test, such as HTTP Request Sampler, FTP Request Sample, TCP Request Sample, JDBC Request Sampler and so on. Each different type of sampler can send different types of requests to the server according to the set parameters.

7. Post processor: responsible for working after the request, often getting the returned value.

8. Assertion: used to determine whether the result of the request response is as expected by the user.

9. Listener: responsible for collecting test results and determining how the results are displayed.

Logic controller: you can customize the behavior logic of JMeter to send requests, which can be used in conjunction with Sampler to simulate complex request sequences.

Scope and execution order of Jmeter components

1. Component scope

Configuration components: affect all components within their scope of action.

Preprocessor: executes in front of each sampler element within its scope.

Timer: every sampler within its scope is valid

Post processor: executes after each sampler element within its scope.

Assertion: the result of execution of each sampler element is checked within its scope of action.

Listener: collects and presents information about each sampler element within its scope of action.

Summary: judge the scope of each component from the hierarchical structure of each component.

two。 Component execution order:

Configuration element-> pre-processor-> timer-> Sampler-> Post processor-> assertion-> listener

Note:

1. Components such as pre-processors, post-processors, and assertions only work on samplers, so if there are no samplers in their scope, they will not be executed.

two。 If there are multiple components of the same type in the same scope, the components are executed in the order in which they are in the test plan.

Sixth, Jmeter interface testing process

The basic steps for interface testing with Jmeter are as follows:

1. Test plan

two。 Thread group

3.HTTP Cookie Manager

Default value of 4.Http request

5.Sampler (HTTP request)

6. Assertion

7. Listeners (view result trees, graphical results, aggregate reports, etc.)

7. Detailed explanation of Jmeter interface testing process

1. Test plan

Open Jmeter and Test Plan appears on the left side of the menu. Here we can understand the test plan as a new blank project under which a series of interfaces can be added.

2. Thread group

Add method: right-click Test Plan- > add-> Thread (user)-> Thread Group.

Component description: a thread group can be thought of as a virtual user group, and each thread in the thread group can be understood as a virtual user.

(1) number of threads: the number of virtual users. The number of threads is set, that is, the number of virtual users

(2) Ramp-Up time (seconds): set the length of time for all virtual users to start. If the number of threads is 20 and the preparation time is 10 seconds, it takes 10 seconds to start 20 threads. That is, an average of 2 threads are started per second.

(3) number of loops: the number of requests sent by each thread. If the number of threads is 20 and the number of loops is 10, each thread sends 10 requests. The total number of requests is 20 / 10 / 200. If "forever" is checked, all threads will keep sending requests until the stop button on the toolbar is manually clicked, or the set thread time ends.

3. HTTP Cookie Manager

Add method: right-click thread group-> add-> configure components-> HTTP Cookie Manager.

Component description: HTTP Cookie Manager can store and send cookie like a browser. If you want to send a http request with cookie, cookie manager will automatically store the cookies of the request, and you can use this cookies later if you send a http request from the same site.

4. Default value of HTTP request

Add method: right-click thread group-> add-> configure component-> HTTP request default value.

Component description: the default value of the HTTP request is set to facilitate filling in the following content. Fill in [server name or IP] and [port number] mainly, so that you don't have to enter the IP address and port number every time in subsequent HTTP requests.

5. HTTP request

Add method: right-click thread group-> add-> Sampler- > HTTP request.

Element description: HTTP request includes interface request method, request path and request parameters, etc.

HTTP request for detailed explanation

(1) name: this attribute is used to identify a sampler and a meaningful name is recommended.

(2) comments: there is no effect on the test, only the user records the comment information that the user can read.

(3) the name of the server or the name or IP address of the target server sent by the IP: HTTP request.

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

(5) Protocol: the protocol for sending HTTP requests to the target server, which can be HTTP or HTTPS. The default value is http.

(6) method: the method of sending HTTP request. Available methods include GET, POST, HEAD, PUT, TRACE, OPTIONS, DELETE, etc.

(7) path: target URL path (excluding server address and port)

(8) content encoding: the encoding method of the content. Default is iso8859.

(9) automatic redirection: if this option is selected, when the response to the HTTP request is 302 / 301, the JMeter is automatically redirected to the new page.

(10) use keep Alive: keep the active state between the jmeter and the target server, selected by default

(11) use multipart/from-data for Post: when sending a POST request, use the multipart/from-data method to send it, which is unchecked by default.

(12) send parameters with the request: send URL parameters in the request. For URL with parameters, jmeter provides a simple method of parameterization. Users can set all the parameters in URL in this table, and each row in the table is a parameter value pair (corresponding to the name 1 = value 1 in RUL).

6. Response assertion

Add method: right-click HTTP request-> add-> Sampler-> HTTP request.

Component description: check whether the interface is accessed successfully. If the check fails, it will indicate that the content of the assertion cannot be found, and if it is not prompted, it will be successful.

Apply to

It refers to the scope of assertion. Usually, one request triggers only one request, so you can check "main sample only". If a request can trigger multiple server requests, it can be divided into main sample and sub-sample.

(1) Main sample and sub-samples: acts on main request and sub-request

(2) Main sample only: only works on the main request

(3) Sub-samples only: only works on sub-requests

(4) Jmeter Variable: acting on jmeter variable (enter the name of jmeter variable in the input box)

Test field

Response text (match returned json data), response code (match return code: 404500, etc.), response information (match response information such as "OK"), response header (match response header), request header (match request header), URL sample (match request url link) Include request url and redirect url if there is a redirect, [document (text)] (match the text form of the response data), ignore status (a request has multiple response assertions) The first response assertion is checked, and when the first response assertion fails, you can ignore the response result and proceed to the next assertion. If the next assertion is successful, it is still determined that the transaction is successful), request data (match request data)

Pattern matching rules

Including: the response content contains the content that needs to be matched, that is, the response is successful, and regular expressions are supported.

Matching: if the response content matches exactly what needs to be matched, it means that the response is successful, is case-insensitive, and supports regular expressions.

String: the response content contains the content that needs to be matched before the response is successful. It is case-sensitive and does not support regular expressions.

Equality: the response content must be completely equal to the content that needs to be matched before the response is successful. It is case-sensitive and does not support regular expressions.

No: it is equivalent to reverse. If the result is true, the check box is false.

Or: if you do not want to connect with AND (all patterns must match before the assertion is successful), the OR option can be used to OR multiple assertion patterns (as long as one pattern match, the assertion is successful)

Test mode

It's actually the data of the assertion. Click the add button to enter the data you want to assert.

7. Add listeners

Add method: thread group-> right add-> listener-> View the result tree. Generally, graphical results and aggregate reports are also added.

Element description: the access result of the interface is displayed in a tree, including the request result, the request content, and the response content of the server.

At this point, the study on "how to test the jmeter interface" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report