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

Jmeter Interface Test and data-driven

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

one。 Background

Data-driven Data Driven Testing (DDT) is a method for creating automated tests, or an architecture, which essentially separates test logic from test data by inputting data and using these data to obtain test results.

The advantage of DDT is that test engineers do not have to create a separate test case for each input data, the test is created in an instance, and the input test data and expected results are obtained in the table file.

two。 Jmeter data driven

First, create a url.csv file as input test data, as follows:

The above content can also be edited with a text editor after saving and exiting. Pay attention to punctuation marks.

I am mac os, save the directory as / Users/louiezhou/home/url.csv

This path is used in the csv data settings file

The interfaces to be tested are as follows:

Get method: https://postman-echo.com/get?foo1=bar1

Get method: https://postman-echo.com/get?foo2=bar2

Post method: https://postman-echo.com/post input parameter {"foo1": "bar1", "foo2": "bar2"}

Source of API documents: https://docs.postman-echo.com/?version=latest#078883ea-ac9e-842e-8f41-784b59a33722

Next in jmeter, first create a thread group

Create a normal http request under this thread group, named postman-echo_header, for comparison with the data driver

Add a loop controller

The number of loops is consistent with the number of use cases recommended in the datasheet file.

Add csv data file settings under the Loop Controller

Add an if controller under the loop controller, named if_get

Jmeter version 5.0 +, if controller and old version are slightly different.

The main reason for adding if here is to judge that if it is the get method, it will go to the if_get controller, and if it is the post method, it will go to the if_post controller.

Add a http request under the if_get controller

The naming rule is: ${caseSeq} _ ${apiSeq} _ ${apiName}

Use case number _ API version _ API name, which is more intuitive and easy to understand

${apiType} = https is the API request protocol

${host} = postman-echo.com is defined in a user-defined variable

${url} = / get

${param} = foo1=bar1

The complete splicing is: https://postman-echo.com/get?foo1=bar1

Let's take a look at the if_post of if controller.

Still create a new if controller under the loop controller, named if_post

Create a new http request under if_post. The naming rule is the same as http under if_get.

${param} = {"foo1": "bar1", "foo2": "bar2"}

The request for complete stitching is:

Https://postman-echo.com/post

POST data:

{"foo1": "bar1", "foo2": "bar2"}

Because it is post mode, the input parameter mode is different from get, so you also need to declare a http information management header under this http.

This is the end of the main process. Let's take a look at the bits and pieces.

Add an assertion to each http request

Although their expected values are all variables ${expectValue}, the actual values are different.

Expected value for use case C001: ${expectValue}: foo1=bar1

Expected value of use case C002 ${expectValue}: foo2=bar2

Expected value of use case C003 ${expectValue}: {"foo1": "bar1", "foo2": "bar2"}

Let's take a look at user-defined variables.

Directory hierarchy

Add the corresponding monitoring and you can execute.

Next, let's look at the implementation result.

There are still some parameters not used in the data table file, such as the priority field, you can add the appropriate judgment according to the needs, this space is only to throw a brick to attract jade, if you have a better idea, please throw it over.

Finally, a bowl of chicken soup:

Your current standard of living is determined by your working status three years ago, and how hard you work now will determine your life in three years' time. The software industry is an industry that sails against the current, and if you do not advance, you will fall behind. Now that you have chosen this industry, you have to work hard to "knock".

Today's featured recommendation

JMeter Interface Test-if Controller

JMeter database operation

Jmeter Interface Test-regular expression

JMeter returns garbled code in Chinese

Jmeter interface testing-parameterization

JMeter Interface testing-Basics

Test-impression

Add Wechat to the consulting work

scan a QR code

Welcome self-recommendation and recommendation, need Wechat to push resume!

Please poke the QR code below to learn more.

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

Internet Technology

Wechat

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

12
Report