Best practices for automated testing of JMeter interfaces (recommended collection)

JMeter is an open source load testing tool that can simulate the load of various protocols and applications, including HTTP , FTP, SMTP, JMS, SOAP , and JDBC. When performing interface automation testing, using JMeter can help us quickly build test cases, simulate various scenarios, and discover interface performance problems. Below are some steps and tips for automated testing of JMeter interfaces.

step

Step 1: Create a test plan

In JMeter , a test plan is the highest level of testing, which contains various elements and configurations such as thread groups, assertions , listeners, etc. Testers need to create a new test plan in JMeter and add the necessary elements and configurations.

To create a new test plan, choose: File > New > Fill in the plan name.

Step 2: Add Thread Group

In the test plan, the tester needs to add one or more thread groups. The thread group is the basic unit of testing, which defines the number of concurrent users, duration, and other properties of the test. Testers need to set the properties of the thread group according to the requirements.

To create a thread group, right-click the test plan and select: Add > Thread (User) > Thread Group.

Fill in the thread group information.

  • Number of threads: 10 threads is to simulate 10 users.
  • Ramp-Up time (seconds): Thread preparation time. If the number of threads is 10 and the preparation time is 10, it takes 1 second to start 1 thread.
  • Cycles. If the number of threads is 10 and the number of loops is 10, then each thread sends 10 requests. The total number of requests is 10*10 = 100. If "Forever" is checked, all threads will keep sending requests until manually stopped.
现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

Step 3: Add a sampler

A sampler is a core component of JMeter testing that simulates actions performed by the user. Testers need to add one or more samplers and set their properties. Common sampler types include HTTP requests, TCP requests, FTP requests, JDBC requests, and more.

Here we take adding an HTTP request as an example. To add an HTTP request, right-click on the thread group and select: Add > Sampler > HTTP Request.

Fill in the HTTP call information.

The passed data is jsonin the format, so add the header information: Content-Type:application/json. Right-click on the HTTP request and select: Add > Config Elements > HTTP Header Management.

Add header information: Content-Type:application/json.

Step 4: Add assertions

Assertions are an important component in JMeter testing and are used to verify that the server's response is as expected. Testers need to add one or more assertions and set their properties.

Common assertion types include response assertions and JSON assertions:

  • Response assertions include: text, response code, response header, response time, etc.
  • JSON assertions allow users to specify a JSON path expression and verify that the JSON response conforms to that expression.

response assertion

Add Response Assertion: Right-click Interface > Add > Assertion > Response Assertion.

Make an assertion that the response text contains the string "Apple":

Make assertions on HTTP response codes:

JSON assertion

Add JSON Assertion : Right click Interface > Add > Assertion > JSON Assertion.

Make an assertion on the total returned by the interface:

Make an assertion on the first item name of the data returned by the interface:

The above JSON Path refers to the JSON path expression. An expression consists of a series of property names and array indices: starting with "$.", separated by "." and "[]". For example, the following JSON response:

  "name": "John",
    "age": 30,
    "cars": [
        {
            "name": "Ford",
            "models": [
                "Fiesta",
                "Focus",
                "Mustang"
            ]
        },
        {
            "name": "BMW",
            "models": [
                "320",
                "X3",
                "X5"
            ]
        }
    ]
}

The corresponding value can be obtained using the following expression:

  • $.name: Gets "John".
  • $.cars[0].name: Gets "Ford".
  • $.cars[1].models[2]: get "X5".

Assertion result

Run the use case. If the response matches the assertion, nothing happens. Otherwise, you will see an error message in the result tree listener.

Step 5: Add Listeners

Listener is another important component in JMeter testing, it is used to collect test results and generate reports. Testers need to add one or more listeners and set their properties. Here are some commonly used JMeter listeners:

  • Aggregated Reports: Provides information on transaction response times, throughput, and error rates.
  • View Results Tree: Displays the response for each request, including request headers, request body, and response body.
  • Listener Graphical Results: Visualize test results for easier analysis of performance issues.
  • Assertion result: Verifies that a response satisfies a specific condition.
  • Distributed Load Test Graph: Shows the load on different servers.

Add a listener: Right-click on the thread group (or sampler) > Add > Monitor > specific monitor. Here we take the most commonly used "View Result Tree" as an example.

Step 6: Run the test plan, view the report

After testers finish configuring the test plan, they can run the test plan and collect test results. Testers can generate reports through the listener and adjust the configuration of the test plan based on the results.

After the use case finishes running, you can see the corresponding results in different configuration monitors.

View the result tree:

Summary report:

Graphical result:

Skill

Working with CSV data files

If you need to simulate multiple scenarios, you can use CSV data files. You can save different request parameters in CSV file and then use CSV data file to configure request parameters in JMeter. In this way, multiple test cases can be quickly generated to improve test efficiency.

Using JMeter plugins

There are many JMeter plugins that can extend its functionality. For example, you can use the JSON Path Extractor plugin to extract specific fields from the JSON data returned by the interface. You can also use the Response Assertion plug-in to verify that the results returned by the interface are as expected.

If you need to use a plugin, you need to follow the steps below to install it:

1. Download the plugin manager

First, you need to download the JMeter Plugin Manager. Plugin Manager is a tool for installing and upgrading JMeter plugins. You can download the latest version of the plugin manager on the official website.

2. Install the plugin manager

Copy the downloaded plugin manager file to the lib/ext directory of JMeter, and restart JMeter.

3. Install the plug-in

Open JMeter and select Options -> Plugins Manager. In the Plugins Manager interface, you can search for the plugin you want to install, and click the Install button to install it.

4. Restart JMeter

After installing the plugin, you need to restart JMeter for it to take effect.

Use distributed testing

If you need to simulate a large number of concurrent users accessing the interface, you can use JMeter's distributed testing capabilities. You can distribute test plans to multiple JMeter clients, running multiple thread groups simultaneously, simulating a large number of concurrent users accessing the interface. This can improve test efficiency and discover interface performance problems.

In short, using JMeter for interface automation testing is a fast, efficient and reliable testing method. Through reasonable configuration and skills, you can find interface performance problems and improve the quality and stability of applications.

The following are supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

Information acquisition method:

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/132461451