How to use jmeter for interface testing? What is the jmeter interface test process like?

foreword

We will use different tools to learn automated testing, so today I want to talk to you about the detailed explanation of the Jmeter interface testing process, and go straight to the topic without talking nonsense.

1. Introduction to jmeter

Jmeter is a java open source project developed by Apache, so it must be based on the java environment if you want to use it;

Jmeter adopts multi-threading, allowing concurrent sampling through multiple threads or simultaneous sampling of different functions through independent threads.

Two, jmeter installation

First you need to install jdk (preferably the latest version);

Next, go to the official website to download the latest jmeter version;

Then configure the environment variables of jmeter;

Finally, double-click jmeter.bat or enter jmeter in the "Command Prompt" to run jmeter.

For specific installation steps, please check online

3. Set the Chinese interface of jmeter

Enter the bin directory of jmeter, find the "jmeter.properties" file, open the file and search for "language", change "#language=en" to "language=zh_CN", save it and then open jmeter to permanently change to the Chinese environment.

Fourth, the main components of jmeter

(1) Test plan: It is the starting point for testing using JMeter, and it is the container for other JMeter test components

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

(3) Configuration element: maintain the configuration information required by Sampler, and modify the content of the request according to actual needs.

(4) Preprocessor: 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 (Sampler): It is the smallest unit for sending requests to the server in performance testing and recording response information and response time, such as: HTTP Request Sampler, FTP Request Sample, TCP Request Sample, JDBC Request Sampler, etc., each Different types of samplers can send different types of requests to the server according to the set parameters.

(7) Post-processor: Responsible for working after the request, and commonly used to obtain the returned value.

(8) Assertion: It is used to judge 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.

(10) Logic controller: You can customize the behavior logic of JMeter sending requests, and it can be used in conjunction with Sampler to simulate complex request sequences.

5. The scope and execution order of Jmeter components

(1) Component scope

  • Configuration element: Affects all elements within its scope of action.
  • Preprocessor: Executed before each sampler element within its scope.
  • Timer: valid for every sampler within its scope
  • Post-processor: Executed after each sampler element within its scope.
  • Assertion: Verify the result after execution of each sampler component within its scope of action.
  • Listener: collect and present the information of each sampler element within its scope of action.
  • Summary: Judging the scope of each component from the hierarchical structure of each component.

(2) Component execution sequence:

  • Configuration element -> preprocessor -> timer -> sampler -> postprocessor -> assertion -> listener

Six, jmeter interface test process steps

(1) Test Plan - Open Jmeter, "Test Plan" appears on the left side of the menu
 

 

(2) Thread group - click "Test Plan" with the mouse

 

  • Number of threads: the number of virtual users. How many threads to set is the number of virtual users to set
  • Ramp-Up time (seconds): Set the time for all virtual users to start. If the number of threads is 20 and the preparation time is 10 seconds, then it takes 10 seconds to start 20 threads. That is, an average of 2 threads are started per second.
  • 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, then 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 request - right-click "Thread Group"

  • HTTP request name: This attribute is used to identify a sampler, it is recommended to use a meaningful name.
  • Comments: have no effect on testing, only user-recorded user-readable comments.
  • Server name or IP: The target server name or IP address sent by the HTTP request.
  • Port number: The port number of the target server, the default value is 80.
  • Protocol: The protocol when sending HTTP requests to the target server, which can be HTTP or HTTPS, and the default value is http.
  • Method: The method of sending the HTTP request, available methods include GET, POST, HEAD, PUT, TRACE, OPTIONS, DELETE, etc.
  • Path: target URL path (excluding server address and port)
  • Content encoding: The encoding method of the content, usually UTF-8.
  • Automatically redirect: If this option is checked, JMeter will automatically redirect to a new page when the HTTP request is sent and the response is 302/301.
  • Use multipart/from-data for Post: When sending a POST request, use the multipart/from-data method to send, which is not selected by default.
  • Send parameters with the request: Send URL parameters in the request. For URLs with parameters, jmeter provides a simple way to parameterize. Users can set all parameters in the URL in this table, and each row in the table is a parameter-value pair (corresponding to name 1=value 1 in RUL).

(4) Add assertion—response assertion 

(5) Add listener - view result tree, aggregate report

Summarize

 

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you! Partners can click the small card below to receive  

Guess you like

Origin blog.csdn.net/okcross0/article/details/130487451