Comparable to postman? Do you know this domestic test tool

A use case without test data is like a pan of loose sand, and it can’t run after two steps.
Without test data, the so-called functional tests and performance tests are all without rice. But I found a very strange thing, that is, few people in the industry emphasize the importance of test data, and no one in the market is even in the business of test data.

So far, testers still rely on manual writing to create test data, and just type in similar data such as phone numbers, ID numbers, and addresses to make do with it.
Or use Python or js scripts to run some test data. Of course, this requires you to be able to write scripts and be familiar with the back-end business interface.

This brings about two types of problems:
1. For projects with simple and routine business data, it is no problem to manually type a few test data temporarily to run the use case; but if
you are in an industry such as e-commerce, insurance, or banking, project data often has specific data structures and business constraints.

2. The test execution schedule of most projects is very tight, and there is often no time to write data scripts. Besides, debugging data scripts is also very time-consuming, especially when the business is related to multiple interfaces and systems, and the back-end interface is still under development.

Create high-availability test data at low cost and quickly
So I have been looking for some tools that can be used to create data for a while, and even lower the requirements for semi-finished products, as long as it can meet my needs for quick and low-cost production of test data.

Later, I found a tool called Apifox, which is not dedicated to test data itself, but closer to domestic Postman. Its own positioning is Apifox=Postman+Swagger+Jmeter+Mock, that is, it integrates interface document management, interface debugging, testing, and mock functions.

But I take what I need and combine its mock and interface automation functions, and it becomes a test data factory tailored for me. Next, I will share with you how to use this tool to create test data based on my experience in the past few days.

According to the type of test data, we divide it into conventional data and proprietary data. Conventional data such as name, age, mobile phone number, email address, ID number, etc.; proprietary data such as waybill number, logistics data, order number, etc. of e-commerce projects
. This part can be realized through Apifox's mock intelligence engine.

According to the difficulty of creating data, it can be divided into data that can be directly generated by a single interface and test data that requires intermediate variables and is generated through multiple interfaces. This part can be realized through interface automation on the basis of mock.

In order to make the constructed test data more in line with business requirements, on this basis, you can add data range constraints to the test data, mock expectations or use mock custom scripts.

Basically follow three steps: first construct the test data field, then construct the interface response data, and modify the test data to make it more in line with the business data requirements.

Start creating data
Before creating data, we need an interface document. The basic rule of creating data is to create data by running the interface.
Apifox supports one-click import of interface documents in more than 20 formats such as Swagger, Postman, and yapi, so no matter what interface management tool your team uses, it can basically be imported painlessly.

If the interface documents you need to develop are in word or html format, then first ask why you still use things from the web 1.0 era in 2022. Is it because the village has not yet connected to the Internet? Then curse and manually copy the interfaces into apifox one by one.

After importing and copying, a neat project interface page is as follows, and then you can start working.

 Use the mock function to create data fields
For routine data in the test data, such as name, phone number, email, address, etc., Apifox has built-in a batch of mock rules.
As shown below, Apifox's mock rules are compatible with the syntax of mock.js, and can flexibly construct data rules through regular expressions. You can view all built-in rules and add custom rules in Project Settings-Function Settings-mock Settings.

It is very simple to use, select the interface corresponding to the test data, select the number creation rule corresponding to the variable in the parameters of the interface request and response, save and initiate the request, and the corresponding data will be generated every time. Example: We use the post interface to generate pet data. In the request parameter mock rule box, select the number creation rule that meets the requirements of this field and save and initiate the request

 Then the interface saves and returns the corresponding pet data:

Generating proprietary business data
The routine test data generated above is constructed directly using the built-in number creation rules. The operations we do are basically multiple-choice questions. This is indeed in line with what we said before, low-cost, high-efficiency test data.
If it is dedicated business data in some vertical industries, such as the logistics number, order number, policy number and other data just mentioned.

There are no ready-made mock rules in Apifox, but it provides custom mock rules to meet such needs.
There is no need for complicated code here, and the number creation logic can be completed through a line of regular expressions. As for whether the written regular expression can accurately summarize the data rules, it can be verified by some online regular expression checkers. After the verification is successful, it will be filled in the mock rules.

Example: Assuming that the project involves the waybill number of SF Express in the logistics industry, you can create a custom mock rule in Project Settings - Smart Mock Settings, fill in a correct regular expression, and then use this rule in the interface response parameters

 Initiate an interface request containing this field to get the waybill number data that meets business requirements:

Create data in batches

If you need to generate multiple pieces of test data, you can 接口设计页面-请求参数set dynamic values ​​in . The settings of dynamic values ​​also follow the mock rules. Dynamic values ​​make the data submitted each time different, and correspondingly generate different new test data.

Save the use case, import it into the automated test and execute it 10 times in a loop, and 10 pieces of test data will be generated.

Use interfaces to automatically create scene data
Sometimes a test data may require intermediate data to be generated, which requires multiple interfaces to be called, involving parameter calls between interfaces and interface association issues. Here I generally use the interface automation function of apifox. Since this article does not specifically introduce interface automation, I will only briefly mention three key issues in using interface automation to create test data:

The parameter use case automatically generates the response data structure of a single interface. As mentioned above, you only need to save the configured use case as a parameter, and then bind this use case in the automated test-new test case-import step. The use case is imported with one key. According to the interface required to execute a business scenario, drag and sort according to the calling order to simulate the actual operation scenario

接口变量提取和接口关联Going back to the single interface use case, extract the parameters for the downstream interface into a global variable, and call the variable in the request parameters of the interface that needs to use the upstream interface variable.

Finally, execute the entire test case to complete the acquisition of the final test data.

Use mock expectations and customize mock scripts to improve test data
. The generated data is no problem in terms of data structure, but there may be business constraints in some test scenarios, and more accurate test data is needed. Data constraints can be used to customize mock scripts.

Data constraints After determining the data type of the response data, such as string, boolean, etc., the data range can be further restricted in the request parameters-advanced settings. For example, for a parameter in the body, the data type is integer, and the range of data changes can be narrowed in the advanced settings

Management of test data

For the number creation script written in code, usually only the person who wrote it knows the specific number creation logic, and it will be more difficult to maintain if this small partner leaves the job.

But with this tool, the number creation logic is relatively simple, and the entire team can see the specific and detailed rules, and the script will not be abolished just because someone in the team leaves.

Then, because the number creation is realized through the interface request, the number creation rules are attached to the interface request and response parameters, so if the version is iterated and the interface changes, then if the number creation rules need to be changed, they can be changed directly on the interface document page, and there is no need to modify the script.

Especially if the interface adds or deletes parameters, or modifies the data type and data structure, basically what needs to be changed is a regular expression, and then select a new number creation rule for the corresponding parameter page.

The maintenance difficulty is so simple that I don't even think it can be called maintenance-it's just a change.

download

After introducing several methods of using Apifox to create test data, if you are interested, you can download it and try it yourself. The software is free and you don’t need to configure anything. You can directly download it from the official website and install it.

Official website address www.apifox.cn

 Friends who are doing the test can come in and communicate. The group has compiled a lot of learning materials and interview questions, project resumes, etc.... 

Guess you like

Origin blog.csdn.net/2301_76643199/article/details/131683795