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 testing practice-dynamic data Verification

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

Share

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

JMeter Interface testing practice-dynamic data Verification

When it comes to verification, we have to say Assertion. First, let's take a look at the definition of assertion given by the official JMeter.

It is used to check whether the response data obtained in the test is in line with the expectation, so as to ensure that the data interaction in the testing process is consistent with the expectation.

The purpose of using assertions:

Add a layer of judgment mechanism to the return level of request, because the success of request does not mean that the result must be correct. A Sampler can add multiple different forms of assertions, according to your inspection requirements to add the corresponding assertions, when all the assertions under the Sampler have been passed, that is the success of the request.

So the question is, what if the content to be judged (expected content) is changing and sometimes uncertain?

For example:

Click Coldplay Technology 3C in some east, and the returned categories are computers, digital, mobile phones, audio and video, games, mobile phone accessories, * * second-hand, etc., assuming that due to the adjustment of business cooperation, this classification often has to change, while the business unit adjusts the classification. The testing department may not be able to notify in time of such changes, there will be problems using assertions. Your script will often fail because the assertion fails.

So how to solve it? Looking down, or continuing the above example, most of the adjustment and classification of business units are implemented through internal backend management systems such as CMS, and the adjusted data is finally stored in DB. As long as you get the data from DB and compare them with the data returned by the API to determine whether the two are consistent or not, you can meet the needs of business changes.

Let's introduce the core of the whole idea.

In order to simplify the demonstration, we omitted some steps to get an array object from DB, the data in which is dynamic, and then send it to another interface assuming Baidu, which takes the contents of the array as keywords to search one by one and returns different results. Check whether the keywords obtained by Baidu are consistent with the dynamic data in DB.

In order to make the demonstration convenient and the screenshot more intuitive, and to avoid coding sensitive company information, switch to the local database first, where the information is stored as follows:

The idea is to take out the contents of the sequence field and put it into an array, where sequence may change at any time, and then pass it to Baidu as a keyword search.

The first step is to create a JDBC connection to establish a connection with the database.

How to set the parameters in JDBC connection has been introduced in the previous tweet, so I won't expand this article. I can't see the official account jmeter database connection clearly.

The second step is to create a jdbc request, which is used to add, delete, modify and check SQL.

We will explain the two nouns Variable names and Result variable name later.

Query timeout is easy to understand literally, that is, the query timeout setting (in s)

The third step is to create a BeanShell PostProcessor to deal with array objects

Beanshell script writing style is not fixed, just follow such a logic, first know the size of the array object, and then use a loop to output the contents of the object one by one, as for the use of for loop or while loop and so on depends on personal preference, so where does the sequence value come from?

Variable names that we haven't introduced yet.

How to use the Variables names parameter:

The Jmeter website explains that if you set a value for this parameter, it will save the data returned by the sql statement and the total number of rows returned. If the sql statement returns 2 rows and 3 columns, and variables names is set to A ~ C, then the following variables will be set to:

Number of rows (total lines)

Column 1 = column 1, row 1

Column 2 = column 1, row 2

Total rows (number of rows)

Column 1 = column 3, row 1

Column 2 = column 3, row 2

If the return result is 0, then An and C # will be set to 0, and other variables will not set values.

If you return six rows of data the first time and only three rows of data the second time, the extra three rows of data variables will be cleared the first time.

You can use ${Abigail #}, ${Agg1}... To get the corresponding value.

It seems to be a bit difficult to understand, it doesn't matter, let's focus on focus in this actual combat, and other knowledge points will be slowly eaten up later. Fill in the variable name you want to use here in variable name, that is, the variable name to be used in the later interface (or beanshell).

Array objects and contents have been obtained, so how to pass them to Baidu interface one by one? Another function to be used here is the counter, which can be found in the configuration element-> counter.

Step 4 create a counter

The function of counter

Jmeter officials have explained that if you need to apply a large amount of data, and the requirements can not be repeated or need to be self-increasing, then you can use counters to do so.

Counter (counter): allows the user to create a counter that can be referenced within a thread group.

The counter allows the user to configure a Starting value, an increment, a Max value, loop to the maximum, then start over and continue until the end.

There is also a reference name, which will be introduced later.

The fifth step is to create a http sampler named Baidu and add a loop controller

Because the extracted data is an array, it needs to be assigned to Baidu interface one by one.

Baidu complete interface can be obtained with tools or F12, wd is Baidu keyword assignment, with the function V plus variable form, here see a deja vu N, that is, the reference name in the counter.

The official function _ _ V is interpreted, which can be used to execute the variable name expression and return the execution result. It can be used to perform nested function references.

Because the sequence stores 7 records in db, we set the loop 7 times in the loop controller.

Step 6: create the result tree. See the result.

Okay, let's execute the script.

The data found in jdbc request SQL is consistent with that in DB, the first figure in this article. The Baidu interface is executed seven times, and each time the data should be the corresponding seven different values in db.

Let's take a look at debug sampler.

You can understand the meaning of setting Result variable name to test_seq in jdbc request and Max value=$ {sequence_#} in counters.

This is the end of the example, using the jmeter sampler + logic controller + front, post-processor + assertion + listener to form the whole practical step exercise.

To quote a famous person:

Open and innovative, confident and humble, build a technical capability layout that is known to me, used by me and owned by me.

Today's recommended reading articles are recommended

Why do interface testing?

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