Test data import method, device, equipment and storage medium
By obtaining and converting test data packets based on preset scripts in interface testing, generating and executing target script files, the inefficiency of manual input and external file methods in interface testing is solved, and efficient parameter assignment and test data introduction are achieved.
Patent Information
- Application Number
- CN202010713896.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-20
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2040-07-20
AI Technical Summary
In interface testing, the use of manual input or introduction of external files has problems such as increasing the cost of testing time and inability to meet the parameter reassignment, resulting in low testing efficiency.
When receiving interface test requests, the test packet is obtained based on the preset script, converted into multiple dictionary objects, and the target script file is generated. Execute the target script file, introduce the dictionary object into the initial test case, and perform parameter assignment to form the target test case.
It realizes the rapid introduction of test data, accurate parameter assignment, and improves the efficiency of interface testing.
Smart Images

Figure CN113961443B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing technology, and in particular to a method, device, equipment and storage medium for introducing testing data. Background Art
[0002] When performing interface testing, testers need to assign values to the interface parameters, which is mainly done during the testing process. When using the Postman tool, there are two sources of test data for parameter assignment: manual input and external file introduction. Manual input is to test the interface while assigning values, and external file introduction is to save all variables in a file, and when all test cases are written and run in batches, the values are uniformly taken from the file.
[0003] The manual input method can change the value while sending the request, but manual input will increase the test time cost; the external file method cannot meet the requirement of re-assigning parameters according to each request when performing automated testing. Therefore, using manual input or introducing external files to perform interface testing will increase the test time cost and cannot meet the requirement of re-assigning parameters, resulting in low efficiency of interface testing. Summary of the invention
[0004] The main purpose of the present invention is to provide a method, device, equipment and storage medium for introducing test data, aiming to solve the technical problem of low test efficiency when performing interface testing by manual input or introducing external files.
[0005] To achieve the above object, an embodiment of the present invention provides a method for introducing test data, the method for introducing test data comprising:
[0006] When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script;
[0007] Convert the test data packet into a plurality of dictionary objects, and generate a target script file according to the plurality of dictionary objects;
[0008] Execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test.
[0009] Preferably, the step of introducing the plurality of dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assigning values to the initial test case based on the plurality of dictionary objects to form a target test case for the interface test comprises:
[0010] Parsing the interface test request to obtain multiple test information of the interface test request;
[0011] According to the multiple test information, multiple dictionary objects in the target script file are searched to determine target dictionary objects corresponding to the multiple test information respectively;
[0012] Based on the multiple test information, the multiple target dictionary objects are respectively introduced into the initial test cases corresponding to the interface test request, and the initial test cases are assigned parameters based on the multiple target dictionary objects to form target test cases for interface testing.
[0013] Preferably, the step of assigning parameters to the initial test case based on the plurality of target dictionary objects to form a target test case for the interface test comprises:
[0014] For the multiple target dictionary objects, perform the following steps respectively:
[0015] According to the variable attributes in the target dictionary object, from the variable attribute column of the initial test case, retrieve the target variable attribute with the same name as the variable attribute;
[0016] Insert the variable value in the target dictionary object into the variable value column of the initial test case, the space corresponding to the target variable attribute, and assign the initial test case a value;
[0017] Until the multiple target dictionary objects complete the assignment of the initial test case, the target test case of the interface test is generated.
[0018] Preferably, the step of obtaining a test data packet corresponding to the interface test request based on a preset script includes:
[0019] Obtaining the interface document of the interface to be tested in the interface test request, and extracting key fields from the interface document;
[0020] Execute the preset script and obtain the test data packet by querying the key field in the preset database.
[0021] Preferably, the step of converting the test data packet into a plurality of dictionary objects and generating a target script file according to the plurality of dictionary objects comprises:
[0022] Reading multiple variable attributes and multiple variable values of the test data packet;
[0023] Respectively associating each variable attribute in the test data packet with a variable value corresponding to each variable attribute to obtain a plurality of key-value pairs;
[0024] The plurality of key-value pairs are converted into a plurality of dictionary objects, and the plurality of dictionary objects are written into an initial script file to form a target script file.
[0025] Preferably, the step of executing the target script file includes:
[0026] Parsing the target script file to determine whether the target script file is a file of a preset type;
[0027] If the target script file is a file of a preset type, executing the target script file;
[0028] If the target script file is not a file of a preset type, the target script file is converted into a type, and the target script file after the type conversion is executed.
[0029] Preferably, the step of forming a target test case for the interface test comprises:
[0030] When a data update request is detected, the editing script is executed to insert the data to be updated into the preset database;
[0031] Execute the update script to insert the data to be updated into the preset database.
[0032] To achieve the above object, the present invention further provides a device for introducing test data, the device for introducing test data comprising:
[0033] An acquisition module, configured to, when receiving an interface test request, acquire a test data packet corresponding to the interface test request based on a preset script;
[0034] A conversion module, used for converting the test data packet into a plurality of dictionary objects, and generating a target script file according to the plurality of dictionary objects;
[0035] An introduction module is used to execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test.
[0036] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a test data introduction device, which includes a memory, a processor, and a test data introduction program stored in the memory and executable on the processor, and the test data introduction program implements the steps of the above-mentioned test data introduction method when executed by the processor.
[0037] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a storage medium, on which a test data importing program is stored, and when the test data importing program is executed by a processor, the steps of the above-mentioned test data importing method are implemented.
[0038] The embodiment of the present invention provides a method, device, equipment and storage medium for introducing test data. When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script; the test data packet is converted into multiple dictionary objects and a target script file is generated; the target script file is executed, multiple dictionary objects in the target script file are introduced into an initial test case corresponding to the interface test request, and the initial test case is assigned to form a target test case for the interface test. The present invention obtains the test data packet required for the test through a preset script, and generates a target script file that can be recognized by an interface test tool. When executing the target script file, the test data is quickly introduced by introducing the dictionary object in the test data packet into the initial test case, and the parameter assignment is accurately completed according to the dictionary object, so as to obtain a target test case for performing the interface test, thereby improving the test efficiency of the interface test. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A schematic diagram of the structure of the hardware operating environment involved in the embodiment of the test data introduction method of the present invention;
[0040] Figure 2 A schematic diagram of a flow chart of a first embodiment of a method for introducing test data of the present invention;
[0041] Figure 3 A schematic diagram of a flow chart of a second embodiment of a method for introducing test data of the present invention;
[0042] Figure 4 Schematic diagram of functional modules of a preferred embodiment of the device for introducing test data of the present invention.
[0043] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0044] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0045] The embodiment of the present invention provides a method, device, equipment and storage medium for introducing test data. When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script; the test data packet is converted into multiple dictionary objects and a target script file is generated; the target script file is executed, multiple dictionary objects in the target script file are introduced into an initial test case corresponding to the interface test request, and the initial test case is assigned to form a target test case for the interface test. The present invention obtains the test data packet required for the test through a preset script, and generates a target script file that can be recognized by an interface test tool. When executing the target script file, the test data is quickly introduced by introducing the dictionary object in the test data packet into the initial test case, and the parameter assignment is accurately completed according to the dictionary object, so as to obtain a target test case for performing the interface test, thereby improving the test efficiency of the interface test.
[0046] like Figure 1 As shown, Figure 1 It is a schematic diagram of the structure of a device for introducing test data of a hardware operating environment involved in an embodiment of the present invention.
[0047] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present invention, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.
[0048] The device for importing test data in the embodiment of the present invention may be a PC, or a portable terminal device such as a tablet computer or a portable computer.
[0049] like Figure 1 As shown, the device for introducing the test data may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0050] Those skilled in the art will understand that Figure 1The structure of the test data introduction device shown in the figure does not constitute a limitation on the test data introduction device, and may include more or less components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0051] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a test data import program.
[0052] exist Figure 1 In the device shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and perform data communication with the client; and the processor 1001 can be used to call the import program of the test data stored in the memory 1005 and perform the following operations:
[0053] When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script;
[0054] Convert the test data packet into a plurality of dictionary objects, and generate a target script file according to the plurality of dictionary objects;
[0055] Execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test.
[0056] Furthermore, the step of introducing the plurality of dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assigning values to the initial test case based on the plurality of dictionary objects to form a target test case for the interface test includes:
[0057] Parsing the interface test request to obtain multiple test information of the interface test request;
[0058] According to the multiple test information, multiple dictionary objects in the target script file are searched to determine target dictionary objects corresponding to the multiple test information respectively;
[0059] Based on the multiple test information, the multiple target dictionary objects are respectively introduced into the initial test cases corresponding to the interface test request, and the initial test cases are assigned parameters based on the multiple target dictionary objects to form target test cases for interface testing.
[0060] Furthermore, the step of assigning parameters to the initial test case based on the multiple target dictionary objects to form a target test case for the interface test includes:
[0061] For the multiple target dictionary objects, perform the following steps respectively:
[0062] According to the variable attributes in the target dictionary object, from the variable attribute column of the initial test case, retrieve the target variable attribute with the same name as the variable attribute;
[0063] Insert the variable value in the target dictionary object into the variable value column of the initial test case, the space corresponding to the target variable attribute, and assign the initial test case a value;
[0064] Until the multiple target dictionary objects complete the assignment of the initial test case, the target test case of the interface test is generated.
[0065] Furthermore, the step of obtaining a test data packet corresponding to the interface test request based on a preset script includes:
[0066] Obtaining the interface document of the interface to be tested in the interface test request, and extracting key fields from the interface document;
[0067] Execute the preset script and obtain the test data packet by querying the key field in the preset database.
[0068] Furthermore, the step of converting the test data packet into a plurality of dictionary objects and generating a target script file according to the plurality of dictionary objects comprises:
[0069] Reading multiple variable attributes and multiple variable values of the test data packet;
[0070] Respectively associating each variable attribute in the test data packet with a variable value corresponding to each variable attribute to obtain a plurality of key-value pairs;
[0071] The plurality of key-value pairs are converted into a plurality of dictionary objects, and the plurality of dictionary objects are written into an initial script file to form a target script file.
[0072] Furthermore, the step of executing the target script file includes:
[0073] Parsing the target script file to determine whether the target script file is a file of a preset type;
[0074] If the target script file is a file of a preset type, executing the target script file;
[0075] If the target script file is not a file of a preset type, the target script file is converted into a type, and the target script file after the type conversion is executed.
[0076] Further, after the step of forming the target test case of the interface test, the processor 1001 can be used to call the import program of the test data stored in the memory 1005, and perform the following operations:
[0077] When a data update request is detected, the editing script is executed to insert the data to be updated into the preset database;
[0078] Execute the update script to insert the data to be updated into the preset database.
[0079] In order to better understand the above technical solution, exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0080] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0081] Reference Figure 2 , the first embodiment of the present invention provides a flow chart of a method for introducing test data. In this embodiment, the method for introducing test data includes the following steps:
[0082] Step S10, when an interface test request is received, obtaining a test data packet corresponding to the interface test request based on a preset script;
[0083] The method for introducing test data in this embodiment is applied to an interface testing system. The interface testing system includes an interface testing tool, a database tool and a preset data table. The preset data table is preferably Excel in this embodiment. The interface testing tool can read data from Excel. The interface testing tool in this embodiment is preferably a Postman tool. Postman is a powerful tool for sending HTTP (Hyper Text Transfer Protocol) requests, which is commonly used in web (World Wide Web) development and interface testing. The database tool is used to establish, use and maintain a database. The database tool in this embodiment can be SQLyog, Navicat, etc. Excel is a spreadsheet for storing data required for interface testing. A SQL (Structured Query Language) script is provided in the database tool, wherein the SQL script is a sql statement containing one or more sql commands. A Python script and an application for executing the Python script are also provided in the system. Python is a cross-platform computer programming language. The Python script imports the xlrd library and has a built-in json (JavaScript Object Notation, JS object notation) library, xlrd is an extension package for reading Excel in Python language, json is a lightweight data exchange format, and the application that executes Python scripts can be PyCharm, Eclipse+PyDev, Visual Studio, etc.
[0084] Furthermore, when an interface test request is received from a user with an interface test requirement, the system obtains the interface document of the interface to be tested, and calls the database tool to execute the preset script, searches the preset database for the test data packet corresponding to the interface test request, extracts and stores the found test data packet, wherein the preset script is preferably an SQL script in this embodiment, and the preset database may be a database such as sqlserver, mysql, oracle, etc. The test data packet includes at least variable attributes and variable values, both of which may be one or more, and the number of variable attributes is equal to the number of variable values.
[0085] Furthermore, the step of obtaining a test data packet corresponding to the interface test request based on a preset script includes:
[0086] Step S11, obtaining the interface document of the interface to be tested in the interface test request, and extracting key fields from the interface document;
[0087] Step S12, executing a preset script, and obtaining a test data packet by querying the key field in a preset database.
[0088] Furthermore, the system obtains the interface document corresponding to the interface to be tested in the interface test request sent by the user, and extracts key fields from the interface document according to the test field information in the interface test request, wherein the number of interfaces can be one or more, and multiple interfaces belong to the same service, and the interface document contains all the information for the normal operation of one or more interfaces, which also contains fields, and the fields are the attributes of the class. Furthermore, after extracting the key fields, the system executes the preset SQL script, uses the key fields as indexes to search in the preset database, and obtains the test data of the interface to be tested in the interface test request. Furthermore, the system exports the test data obtained by the query to the preset data table Excel, so as to quickly import the test data into the interface test tool for parameter assignment.
[0089] Step S20, converting the test data packet into a plurality of dictionary objects, and generating a target script file according to the plurality of dictionary objects;
[0090] Further, the system executes the Python script, reads multiple variable attributes and multiple variable values of the test data packet from the preset data table, and generates multiple variable attributes and multiple variable values into multiple key-value pairs, wherein one key-value pair consists of one variable attribute and one variable value. Further, the system converts the multiple key-value pairs into multiple dictionary objects, and writes the multiple dictionary objects into the initial script file to generate a target script file.
[0091] Furthermore, the step of converting the test data packet into a plurality of dictionary objects and generating a target script file according to the plurality of dictionary objects comprises:
[0092] Step S21, reading multiple variable attributes and multiple variable values of the test data packet;
[0093] Step S22, respectively associating each variable attribute in the test data packet with a variable value corresponding to each variable attribute to obtain a plurality of key-value pairs;
[0094] Step S23, converting the plurality of key-value pairs into a plurality of dictionary objects, and writing the plurality of dictionary objects into an initial script file to form a target script file.
[0095] Furthermore, the system executes a Python script, and reads multiple variable attributes and multiple variable values of a test data packet from a preset data table Excel row by row or column by column by executing a specific read statement. Furthermore, the system associates each variable attribute and the variable value corresponding to the variable attribute. Specifically, a variable attribute and a variable value in the same row of the variable attribute can be combined to obtain a key-value pair. The system executes the above steps multiple times until the multiple variable attributes and multiple variable values of the test data packet read from the preset data table Excel are generated into multiple key-value pairs. Furthermore, the system converts the generated multiple key-value pairs into multiple dictionary objects of Python type through specific conversion statements, so as to directly introduce multiple key-value pairs. Furthermore, the system writes the multiple dictionary objects obtained by conversion into the initial script file representing the script template through the json library in overwrite mode, and obtains the target script file after writing is completed, so as to generate the target test case for testing the interface according to the test data packet required for interface testing by executing the target script file, wherein the overwrite mode is: when a variable attribute or variable value is changed, or a new variable attribute and variable value are appended, all the data is read and then rewritten into the initial script file.
[0096] Step S30, executing the target script file, introducing multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assigning values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test.
[0097] Furthermore, the system calls the interface testing tool Postman to execute the target script file, and by executing the target script file, determines the target dictionary objects corresponding to the multiple test information of the interface test request from the multiple dictionary objects, and introduces the target dictionary objects corresponding to the multiple test information into the initial test case. Furthermore, the system introduces the multiple target dictionary objects determined in the multiple dictionary objects into the initial test case, and assigns values to the initial test case according to the multiple test information respectively by the target dictionary objects corresponding to each test information, and after the target dictionary objects corresponding to each test information have completed the assignment of the initial test case, a target test case for interface testing is formed, so that the result of the interface test can be obtained by executing the target test case.
[0098] Further, the step of forming a target test case for the interface test includes:
[0099] Step S301, when a data update request is detected, obtaining an update script containing the data to be updated;
[0100] Step S302, executing the update script to insert the data to be updated into a preset database.
[0101] It is understandable that before executing the target test case to perform interface testing, the user may want to modify or add variable values for some special reasons and initiate a data update request in the database tool. Furthermore, when a data update request is detected, the system obtains the update script edited by the user containing the data to be updated, and calls the database tool to execute the update script, and inserts the data to be updated that the user needs to update to the target test case into the preset database. It is understandable that when a new interface test request is received, the system obtains an updated test data packet from the preset database by executing the preset script; converts the updated test data packet into a dictionary object, and imports the updated dictionary object into the target script file to generate an update script file, so as to introduce the test data packet into the initial test case according to the update script file, and form a target test case for interface testing.
[0102] The present embodiment provides a method, device, equipment and storage medium for introducing test data. When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script; the test data packet is converted into multiple dictionary objects and a target script file is generated; the target script file is executed, multiple dictionary objects in the target script file are introduced into an initial test case corresponding to the interface test request, and the initial test case is assigned to form a target test case for the interface test. The present invention obtains the test data packet required for the test through a preset script, and generates a target script file that can be recognized by an interface test tool. When executing the target script file, the test data is quickly introduced by introducing the dictionary object in the test data packet into the initial test case, and the parameter assignment is accurately completed according to the dictionary object, so as to obtain a target test case for performing the interface test, thereby improving the test efficiency of the interface test.
[0103] Further, refer to Figure 3 Based on the first embodiment of the method for introducing test data of the present invention, a second embodiment of the method for introducing test data of the present invention is proposed. In the second embodiment, the step of introducing the target dictionary object corresponding to the interface test request into the initial test case and assigning a value to the initial test case to form a target test case for the interface test includes:
[0104] Step S31, parsing the interface test request to obtain multiple test information of the interface test request;
[0105] Step S32, searching the multiple dictionary objects in the target script file according to the multiple test information, and determining the target dictionary objects corresponding to the multiple test information respectively;
[0106] Step S33, based on the multiple test information, the multiple target dictionary objects are respectively introduced into the initial test cases corresponding to the interface test request, and the initial test cases are assigned parameters based on the multiple target dictionary objects to form target test cases for the interface test.
[0107] Further, the system parses the received interface test request, specifically, identifies the request content of the interface test request, and obtains multiple test information representing the information to be assigned of the interface to be tested. Further, the system retrieves multiple dictionary objects in the target script file according to the multiple test information, determines the target dictionary objects corresponding to the multiple test information, specifically, according to the current test information, traverses and searches the multiple dictionary objects in the target script file, and extracts the target dictionary object corresponding to the current test information representing the information to be assigned as the dictionary object required for the interface test, and executes the above steps multiple times until the target dictionary object corresponding to the multiple test information is determined. It can be understood that the multiple test information corresponds to different positions of the initial test case, so it is necessary to introduce the multiple target dictionary objects into the initial test case according to the multiple test information. Further, the system introduces the extracted multiple target dictionary objects into the initial test case according to the multiple test information, and after the introduction is completed, the target dictionary objects are merged into the initial test case according to the test requirements in the multiple test information, and the variable value column corresponding to the variable attribute column in the initial test case is assigned, and the target test case is formed after the assignment is completed.
[0108] Furthermore, the step of assigning parameters to the initial test case based on the multiple target dictionary objects to form a target test case for the interface test includes:
[0109] Step S331, for each of the target dictionary objects, perform the following steps respectively:
[0110] Step S332, according to the variable attributes in the target dictionary object, retrieve the target variable attributes with the same name as the variable attribute from the variable attribute column of the initial test case;
[0111] Step S333, inserting the variable value in the target dictionary object into the variable value column of the initial test case, the space corresponding to the target variable attribute, and assigning a value to the initial test case;
[0112] Step S334, until the multiple target dictionary objects complete the assignment of the initial test case, the target test case for the interface test is generated.
[0113] Further, the system obtains multiple target dictionary objects, and respectively assigns parameters to the initial test case through each target dictionary object, wherein, in addition to basic information and general command statements, the initial test case at least includes a variable attribute column and a variable value column, the variable attribute column can set one or more variable attributes with different variable names, and the variable value column can set one or more variable values with different numerical values. Specifically, the system identifies the naming of the variable attributes in the current target dictionary object, and retrieves the target variable attributes with the same variable attribute naming as the current target dictionary object from the variable attribute column of the initial test case. Further, the system uses the variable value in the dictionary object as the target variable required for interface testing, inserts it into the space in the same row as the target variable attribute, and completes the parameter assignment of the variable value corresponding to the current target variable attribute. After multiple target dictionary objects have completed the step of assigning parameters to the initial test case, a target test case for interface testing is formed to execute the target test case and obtain the test result of the interface test.
[0114] This embodiment obtains test information by parsing the interface test request, and then retrieves the target dictionary object required for this interface test from the target script file according to the test information, assigns parameters to the initial test case through the target dictionary object, and obtains the target test case corresponding to the interface test request. This application can introduce the target dictionary object corresponding to the test information from the target script file according to different interface test requests, and accurately completes the parameter assignment of the interface test according to the target dictionary object, while avoiding manual assignment, reducing time cost, and improving the test efficiency of the interface test.
[0115] Further, based on the first embodiment of the method for importing test data of the present invention, a third embodiment of the method for importing test data of the present invention is proposed. In the third embodiment, the step of executing the target script file includes:
[0116] Step S40, parsing the target script file to determine whether the target script file is a file of a preset type;
[0117] Step S50, if the target script file is a file of a preset type, executing the target script file;
[0118] Step S60: If the target script file is not a file of a preset type, the target script file is converted into a type, and the target script file after the conversion is executed.
[0119] Furthermore, the system obtains the file information of the target script file and identifies whether the original file format contained in the file information is the preset type json. If the format of the target script file is detected to be json, the interface testing tool is called to execute the target script file; if the format of the target script file is not json, indicating that the target script file cannot be directly executed, the system converts the format of the target script file. Specifically, the system converts the target script file from the original file format to the preset json format based on the conversion relationship between the original file format and the preset json format, and executes the target script file after the format conversion, so as to assign parameters to the initial test case and obtain the target test case for interface testing.
[0120] This embodiment parses the target script file to determine whether the target script file is a preset type that can be recognized and executed by the interface testing tool. If so, the target script file is executed; if it is not a preset type that can be recognized and executed by the interface testing tool, the target script file is converted into a type, and then the converted target script file is executed, so that the interface testing tool can recognize and execute the target script file, thereby avoiding an increase in testing time due to the inability of the interface testing tool to recognize the target script file, thereby improving the efficiency of interface testing.
[0121] Furthermore, the present invention also provides a device for introducing test data.
[0122] Reference Figure 4 , Figure 4 This is a functional module diagram of the first embodiment of the device for introducing test data of the present invention.
[0123] The test data introduction device comprises:
[0124] The acquisition module 10 is used to acquire a test data packet corresponding to the interface test request based on a preset script when an interface test request is received;
[0125] The conversion module 20 is used to convert the test data packet into a plurality of dictionary objects, and generate a target script file according to the plurality of dictionary objects;
[0126] The introduction module 30 is used to execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test.
[0127] Furthermore, the acquisition module 10 includes:
[0128] A first acquisition unit, used to acquire an interface document of the interface to be tested in the interface test request, and extract key fields from the interface document;
[0129] The first execution unit is used to execute a preset script and obtain a test data packet by querying the key field in a preset database.
[0130] Furthermore, the conversion module 20 includes:
[0131] A reading unit, used for reading a plurality of variable attributes and a plurality of variable values of the test data packet;
[0132] An associating unit, used to associate each variable attribute in the test data packet with a variable value corresponding to each variable attribute, to obtain a plurality of key-value pairs;
[0133] The conversion unit is used to convert the multiple key-value pairs into multiple dictionary objects, and write the multiple dictionary objects into an initial script file to form a target script file.
[0134] Furthermore, the introduction module 30 includes:
[0135] A first parsing unit, used to parse the interface test request to obtain multiple test information of the interface test request;
[0136] A first retrieval unit, configured to retrieve the plurality of dictionary objects in the target script file according to the plurality of test information, and determine target dictionary objects corresponding to the plurality of test information respectively;
[0137] An assignment unit is used to introduce multiple target dictionary objects into the initial test cases corresponding to the interface test request based on multiple test information, and to assign parameters to the initial test cases based on multiple target dictionary objects to form target test cases for the interface test.
[0138] Furthermore, the introduction module 30 also includes:
[0139] A second execution unit, configured to execute steps S332 to S334 respectively for the plurality of target dictionary objects;
[0140] A second retrieval unit is used to retrieve a target variable attribute having the same name as the variable attribute from the variable attribute column of the initial test case according to the variable attribute in the target dictionary object;
[0141] An assignment unit, for inserting the variable value in the target dictionary object into the variable value column of the initial test case, a space corresponding to the target variable attribute, and assigning a value to the initial test case;
[0142] A generating unit is used to generate a target test case for the interface test until the multiple target dictionary objects complete the assignment of the initial test case.
[0143] Furthermore, the introduction module 30 also includes:
[0144] A second parsing unit, configured to parse the target script file to determine whether the target script file is a file of a preset type;
[0145] A third execution unit, configured to execute the target script file if the target script file is a file of a preset type;
[0146] The fourth execution unit is used to perform type conversion on the target script file if the target script file is not a file of a preset type, and execute the target script file after the type conversion.
[0147] Furthermore, the introduction module 30 also includes:
[0148] A second acquisition unit, configured to acquire an update script containing data to be updated when a data update request is detected;
[0149] The fifth execution unit is used to execute the update script to insert the data to be updated into a preset database.
[0150] In addition, the present invention also provides a storage medium, which is preferably a computer-readable storage medium, on which a test data introduction program is stored. When the test data introduction program is executed by a processor, the steps of each embodiment of the above-mentioned test data introduction method are implemented.
[0151] In the embodiments of the test data introduction device and storage medium of the present invention, all technical features of the above-mentioned test data introduction method embodiments are included, and the description and explanation content are basically the same as those of the above-mentioned test data introduction method embodiments, and will not be repeated here.
[0152] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0153] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0154] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), and includes several instructions for enabling a terminal device (which can be a fixed terminal, such as an IoT smart device, including smart air conditioners, smart lights, smart power supplies, smart routers and other smart homes; it can also be a mobile terminal, including smart phones, wearable networked AR / VR devices, smart speakers, self-driving cars and many other networked devices) to execute the methods described in the various embodiments of the present invention.
[0155] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for introducing test data, characterized in that: The method for introducing test data comprises: When an interface test request is received, a test data packet corresponding to the interface test request is obtained based on a preset script; The step of obtaining a test data packet corresponding to the interface test request based on a preset script includes: Obtaining an interface document of the interface to be tested in the interface test request, and extracting key fields from the interface document, wherein the interface document includes all information on normal operation of one or more interfaces; Execute a preset script and obtain a test data packet by querying the key field in a preset database; Convert the test data packet into a plurality of dictionary objects, and generate a target script file according to the plurality of dictionary objects; The step of converting the test data packet into a plurality of dictionary objects and generating a target script file according to the plurality of dictionary objects comprises: Reading multiple variable attributes and multiple variable values of the test data packet; Respectively associating each variable attribute in the test data packet with a variable value corresponding to each variable attribute to obtain a plurality of key-value pairs; Convert the plurality of key-value pairs into a plurality of dictionary objects, and write the plurality of dictionary objects into an initial script file to form a target script file; Execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test; The step of introducing the plurality of dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assigning values to the initial test case based on the plurality of dictionary objects to form a target test case for the interface test includes: Parsing the interface test request to obtain multiple test information of the interface test request; According to the multiple test information, multiple dictionary objects in the target script file are searched to determine target dictionary objects corresponding to the multiple test information respectively; Based on the multiple test information, the multiple target dictionary objects are respectively introduced into the initial test cases corresponding to the interface test request, and the initial test cases are assigned parameters based on the multiple target dictionary objects to form target test cases for interface testing.
2. The method for introducing test data according to claim 1, characterized in that: The step of assigning parameters to the initial test case based on the multiple target dictionary objects to form a target test case for the interface test comprises: For the multiple target dictionary objects, perform the following steps respectively: According to the variable attributes in the target dictionary object, from the variable attribute column of the initial test case, retrieve the target variable attribute with the same name as the variable attribute; Insert the variable value in the target dictionary object into the variable value column of the initial test case, the space corresponding to the target variable attribute, and assign the initial test case a value; Until the multiple target dictionary objects complete the assignment of the initial test case, the target test case of the interface test is generated.
3. The method for introducing test data according to claim 1, characterized in that: The step of executing the target script file comprises: Parsing the target script file to determine whether the target script file is a file of a preset type; If the target script file is a file of a preset type, executing the target script file; If the target script file is not a file of a preset type, the target script file is converted into a type, and the target script file after the type conversion is executed.
4. The method for introducing test data according to claim 1, characterized in that: The step of forming a target test case for the interface test then includes: When a data update request is detected, an update script containing the data to be updated is obtained; Execute the update script to insert the data to be updated into the preset database.
5. A device for introducing test data, characterized in that: The test data introduction device comprises: An acquisition module, configured to, when receiving an interface test request, acquire a test data packet corresponding to the interface test request based on a preset script; Wherein, the acquisition module is also used for: Obtaining an interface document of the interface to be tested in the interface test request, and extracting key fields from the interface document, wherein the interface document includes all information on normal operation of one or more interfaces; Execute a preset script and obtain a test data packet by querying the key field in a preset database; A conversion module, used for converting the test data packet into a plurality of dictionary objects, and generating a target script file according to the plurality of dictionary objects; Wherein, the conversion module is also used for: Reading multiple variable attributes and multiple variable values of the test data packet; Respectively associating each variable attribute in the test data packet with a variable value corresponding to each variable attribute to obtain a plurality of key-value pairs; Convert the plurality of key-value pairs into a plurality of dictionary objects, and write the plurality of dictionary objects into an initial script file to form a target script file; An introduction module is used to execute the target script file, introduce multiple dictionary objects in the target script file into the initial test case corresponding to the interface test request, and assign values to the initial test case based on the multiple dictionary objects to form a target test case for the interface test; Wherein, the introduction module is also used for: Parsing the interface test request to obtain multiple test information of the interface test request; According to the multiple test information, multiple dictionary objects in the target script file are searched to determine target dictionary objects corresponding to the multiple test information respectively; Based on the multiple test information, the multiple target dictionary objects are respectively introduced into the initial test cases corresponding to the interface test request, and the initial test cases are assigned parameters based on the multiple target dictionary objects to form target test cases for interface testing.
6. A test data introduction device, characterized in that: The test data introduction device includes a memory, a processor, and a test data introduction program stored in the memory and executable on the processor. When the test data introduction program is executed by the processor, the steps of the test data introduction method as described in any one of claims 1 to 4 are implemented.
7. A storage medium, characterized in that: The storage medium stores a test data importing program, and when the test data importing program is executed by the processor, the steps of the test data importing method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Python-based interface automation test method
CN109189684A
Automatic interface testing method based on python
CN110297774A