A method and apparatus for generating test data

By using methods and devices to generate test data, interface structures and abnormal data are processed automatically, solving the problems of manually filling in interface structures and manually creating test data in existing technologies, and improving the efficiency and accuracy of test data acquisition.

CN115904990BActive Publication Date: 2026-05-12INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
INDUSTRIAL AND COMMERCIAL BANK OF CHINA
Filing Date
2022-12-06
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In existing technologies, generating test data requires manually filling in the interface structure and manually creating simulated abnormal data, which results in high time costs and is prone to omissions, making it difficult to efficiently generate test data that meets the requirements.

Method used

By obtaining the header fields of the file to be loaded, an empty data table is created, and baseline data and abnormal test data are generated according to the interface documentation attributes, including test data of types such as duplicate primary keys, mismatched field types, empty fields, and excessively long data.

Benefits of technology

It improved the efficiency of test data acquisition, reduced manual input, ensured the integrity and accuracy of test data, and avoided omissions caused by low quality factors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115904990B_ABST
    Figure CN115904990B_ABST
Patent Text Reader

Abstract

The application provides a method and device for generating test data, relates to the technical field of testing, and can be applied to the financial field or other technical fields.The method comprises the following steps: obtaining a table header field of a to-be-loaded file, creating a data table which is the same as the table header field; the data of the data table except the table header field is empty; generating record data used as benchmark data in the data table according to an interface document attribute of the to-be-loaded file; and generating test data corresponding to an abnormal test data type in the data table according to the interface document attribute and the record data.The device executes the above method.The method and device for generating test data provided in the embodiment of the application can improve the work efficiency of test data acquisition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of testing technology, and more specifically to a method and apparatus for generating test data. Background Technology

[0002] Currently, whether using Oracle databases or switching to the domestic Gaussian database, the file loading function has particularly high requirements for the quality of text data. If there are issues such as duplicate primary keys, data type mismatches, fields that are not allowed to be null but are actually empty, or long values ​​being assigned to short values, the data import may be interrupted. Generally, as a downstream system receiving files, it is necessary to write a special common program to handle these abnormal data to avoid interruptions. As testers on the file receiving side, we clearly feel that there are two pain points that urgently need to be addressed: 1. Testers spend a lot of time manually filling in the text according to the interface structure; 2. Test data that needs to be manually generated to simulate issues such as duplicate primary keys, data type mismatches, fields that are not allowed to be null but are actually empty, or long values ​​being assigned to short values, often has omissions. Summary of the Invention

[0003] To address the problems in the prior art, embodiments of the present invention provide a method and apparatus for generating test data, which can at least partially solve the problems existing in the prior art.

[0004] On one hand, the present invention proposes a method for generating test data, comprising:

[0005] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0006] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0007] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0008] The interface document attributes include a primary key field identifier, and the abnormal test data type includes duplicate primary keys. Correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0009] Insert a row of record information in the data table that has the same data content as each field of the record data, and obtain test data corresponding to the duplication of the data primary key based on the primary key field identifier.

[0010] The interface document attributes include a preset correspondence, and the abnormal test data type includes field data type mismatch; correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0011] Insert a row of record information that has the same data content as each field of the record data into the data table, and replace the field data in the row of record information according to the preset correspondence;

[0012] The preset correspondence includes the correspondence between preset field data types and preset replacement character content;

[0013] Each replacement generates a new row of record information, resulting in test data that does not match the data type of the field.

[0014] The data types of the fields include numeric fields, character fields, and date fields; correspondingly, the replacement of field data in the row of record information according to the preset correspondence includes:

[0015] The numeric, character, and date fields in a row of record information are replaced according to a preset correspondence.

[0016] The preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content.

[0017] The interface document attributes include a non-primary key field identifier, and the abnormal test data type includes fields defined as not allowing null values ​​but with null data; correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0018] Insert a row of record information with the same data content as each field of the record data into the data table, and clear the data of the non-primary key fields in the row of record information according to the non-primary key field identifier to obtain test data corresponding to the field definition that does not allow null and the data is empty.

[0019] The interface document attributes include the field corresponding to the file to be loaded, and the abnormal test data type includes excessively long data. Correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0020] If the field is determined to be a delimiter field or a fixed-length field, then insert a row of record information in the data table that has the same data content as each field of the record data, and add 1 digit of data after the data corresponding to the delimiter field or the fixed-length field to obtain test data corresponding to the excessively long data.

[0021] The method for generating test data, after the step of generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data, further includes:

[0022] Various test data are packaged together to obtain a test data file.

[0023] On one hand, the present invention proposes an apparatus for generating test data, comprising:

[0024] The acquisition unit is used to acquire the header fields of the file to be loaded and create a data table with the same header fields; the data table is empty except for the header fields.

[0025] The first generation unit is used to generate record data in the data table as reference data according to the interface document attributes of the file to be loaded.

[0026] The second generation unit is used to generate test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data.

[0027] In another aspect, embodiments of the present invention provide an electronic device, including: a processor, a memory, and a bus, wherein,

[0028] The processor and the memory communicate with each other via the bus;

[0029] The memory stores program instructions that can be executed by the processor, and the processor can execute the following methods by calling the program instructions:

[0030] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0031] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0032] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0033] This invention provides a non-transitory computer-readable storage medium, comprising:

[0034] The non-transitory computer-readable storage medium stores computer instructions that cause the computer to perform the following methods:

[0035] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0036] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0037] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0038] The method and apparatus for generating test data provided in this invention obtain the header fields of the file to be loaded and create a data table with the same header fields; the data table is empty except for the header fields; record data is generated in the data table as baseline data according to the interface document attributes of the file to be loaded; test data corresponding to the abnormal test data type is generated in the data table according to the interface document attributes and the record data, which can improve the efficiency of test data acquisition. Attached Figure Description

[0039] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:

[0040] Figure 1 This is a flowchart illustrating a method for generating test data according to an embodiment of the present invention.

[0041] Figure 2 This is a flowchart illustrating a method for generating test data according to another embodiment of the present invention.

[0042] Figure 3 This is a flowchart illustrating a method for generating test data according to another embodiment of the present invention.

[0043] Figure 4 This is a schematic diagram of the structure of a device for generating test data according to an embodiment of the present invention.

[0044] Figure 5 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0045] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Here, the illustrative embodiments and descriptions of the present invention are used to explain the present invention, but are not intended to limit the present invention. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other.

[0046] The relevant terminology in the embodiments of the present invention is explained as follows:

[0047] File loading: Data is transferred between two databases via text files, and the text records are imported into the corresponding tables in the databases.

[0048] A test case is a description of a testing task performed on a specific software product. It includes input data, test steps, expected results, etc., and is documented.

[0049] Figure 1 This is a flowchart illustrating a method for generating test data according to an embodiment of the present invention, as shown below. Figure 1 As shown, the method for generating test data provided in this embodiment of the invention includes:

[0050] Step S1: Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0051] Step S2: Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0052] Step S3: Generate test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data.

[0053] In step S1 above, the device obtains the header fields of the file to be loaded and creates a data table with the same header fields; the data table is empty except for the header fields. The device can be a computer device that executes this method, such as a server. It should be noted that the acquisition and analysis of data involved in this embodiment of the invention are authorized by the user. See Table 1 for further explanation:

[0054] Table 1

[0055]

[0056] The header fields can be the partition area code, card BIN, card BIN length, card number length, and generation date from Table 1. These header fields can be manually prepared beforehand in the file to be loaded and then written into Excel. As shown in Table 1, the created data table includes five header fields: partition area code, card BIN, card BIN length, card number length, and generation date. At this point, all other data in Table 1 is empty.

[0057] In step S2 above, the device generates record data in the data table as baseline data based on the interface document attributes of the file to be loaded. It should be noted that since manual review is usually required after generating the test data, to facilitate subsequent manual work (i.e., easy comparison of data differences by human eyes), standardized and easily comparable data can be used as baseline data. For example, all field data content can use maximum values, and fields that are allowed to be empty can remain empty.

[0058] Referring to the above explanation, the record data used as reference data can be generated in the following manner:

[0059] Based on the attributes in the API documentation, generate a record from the data table. All fields in this record will use the maximum value, and fields that are allowed to be empty will remain empty.

[0060] Referring to Table 1, this record corresponds to the row containing "Record Number 1" in Table 1.

[0061] Interface documentation, as the name suggests, is the documentation describing the interface, and it serves as the basis for calling the interface. Correspondingly, interface documentation attributes are the attribute information of the interface documentation. Interface documentation attributes include, but are not limited to, the first three rows of data in Table 1. For example, it may also include primary key field identifiers, preset correspondences, non-primary key field identifiers, and the fields to which the file to be loaded belongs.

[0062] Referring to Table 1, the primary key fields are the two column header fields corresponding to the partition area code and the card BIN, and the non-primary key fields are the remaining column header fields.

[0063] In step S3 above, the device generates test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data. The interface document attributes include a primary key field identifier, and the abnormal test data type includes duplicate primary keys. Correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0064] Insert a row of records into the data table that has the same data content as all fields of the recorded data, and obtain test data corresponding to the duplication of the primary key based on the primary key field identifier. The primary key field identifier can distinguish which header fields are primary key fields. This row of records corresponds to the row containing "Record Number Two" in Table 1. The test data corresponding to the duplication of the primary key are 12345 corresponding to "Region Code" and 123456 corresponding to "Card BIN".

[0065] The interface document attributes include a preset correspondence, and the abnormal test data type includes field data type mismatch; correspondingly, generating test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data includes:

[0066] Insert a row of record information that has the same data content as each field of the record data into the data table, and replace the field data in the row of record information according to the preset correspondence;

[0067] The preset correspondence includes the correspondence between preset field data types and preset replacement character content;

[0068] Each replacement generates a new row of record information, resulting in test data that does not match the data type of the field.

[0069] The field data types include numeric fields, character fields, and date fields; correspondingly, the replacement of field data in the row of record information according to the preset correspondence includes:

[0070] The numeric, character, and date fields in a row of record information are replaced according to a preset correspondence.

[0071] The preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content. As shown in Table 1, the first correspondence is the correspondence between the numeric header field and the letter "A", that is, all the field content in the numeric header field is replaced with the letter "A". The new record information generated by the first replacement corresponds to the row containing "Record Number Three" in Table 1, and the test data corresponding to the data type mismatch of the field is the letter "A".

[0072] The second correspondence is between character header fields and the special letter "!". That is, all the field content in the character header fields is replaced with the special letter "!". The new record information generated by the second replacement corresponds to the row containing "Record Number Four" in Table 1. The test data that does not match the field data type is the special letter "!".

[0073] The third correspondence is between the date header field and "2099 / 12 / 32". This means that all the field content in the date header field is replaced with "2099 / 12 / 32". The new record information generated by the third replacement corresponds to the row containing "Record Number 5" in Table 1. The test data corresponding to the data type mismatch is "2099 / 12 / 32".

[0074] The interface document attributes include a non-primary key field identifier, and the abnormal test data type includes fields defined as not allowing null values ​​but with null data; correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0075] Insert a row of records into the data table that has the same data content as all fields of the record data. Then, based on the non-primary key field identifier, clear the data in the non-primary key fields of this row of records to obtain test data corresponding to the field definition that does not allow null values ​​but has empty data. The non-primary key field identifier can distinguish which header fields are non-primary key fields. This row of records corresponds to the row containing "Record Count Six" in Table 1. The test data corresponding to the field definition that does not allow null values ​​but has empty data consists of columns three through five.

[0076] The interface document attributes include the field corresponding to the file to be loaded, and the abnormal test data type includes excessively long data; correspondingly, generating test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data includes:

[0077] If the field is determined to be a delimiter field or a fixed-length field, a row of records with the same content as the fields of the recorded data is inserted into the data table. One digit is then added after the data corresponding to the delimiter field or the fixed-length field to obtain the test data corresponding to the excessively long data. Delimiter fields and fixed-length fields are standard technical aspects and will not be elaborated further. This row of records corresponds to the row containing "Record Number Seven" in Table 1, where the test data corresponding to the excessively long data is "2022 / 12 / 311".

[0078] After the step of generating test data corresponding to the exception test data type in the data table based on the interface document attributes and the record data, the method for generating test data further includes:

[0079] Various test data are uniformly packaged into a test data file. All test data can be packaged into a BIN file; except for excessively long test data, the length of other fields is the same as the interface documentation definition.

[0080] like Figure 2 As shown, the generation of test data based on the data generation component can be referred to the above description and will not be repeated here. After this step, the data can be maintained manually on the page. For example, add a menu with data query, maintenance and export functions to the IE page. Enter the file name on the page, query the database. If it exists, display the record data of the file and allow editing on the page.

[0081] It also enables a data reset function, which means clicking the reset button will restore the data to the initial test data that has not been modified on the page.

[0082] Test cases can be automatically generated based on the test data, which can be achieved using conventional techniques in this field and will not be elaborated further. The automatically generated test cases and manually written test cases are imported into the test case library. The object under test retrieves the test cases from the library, executes the test cases to perform the tests, and returns the test results as data.

[0083] like Figure 3 The diagram shows the process of exporting test text data based on manual operation, which will not be described in detail here.

[0084] The beneficial effects of the method for generating test data provided in this embodiment of the invention are as follows:

[0085] First is efficiency, directly generating test data and reducing manual input;

[0086] Secondly, it is highly versatile, generating test data according to fixed rules, thus avoiding test omissions due to low tester quality.

[0087] The method for generating test data provided in this embodiment of the invention obtains the header fields of the file to be loaded and creates a data table with the same header fields; the data table is empty except for the header fields; record data is generated in the data table as baseline data according to the interface document attributes of the file to be loaded; test data corresponding to the abnormal test data type is generated in the data table according to the interface document attributes and the record data, which can improve the efficiency of test data acquisition.

[0088] Furthermore, the interface document attributes include a primary key field identifier, and the abnormal test data type includes duplicate primary keys; correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0089] Insert a row of records into the data table that has the same data content as the records in each field, and obtain test data corresponding to the duplicate primary key based on the primary key field identifier. Refer to the above description; further details are omitted.

[0090] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0091] Furthermore, the interface document attributes include a preset correspondence, and the abnormal test data type includes field data type mismatch; correspondingly, generating test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data includes:

[0092] Insert a row of record information in the data table that has the same data content as each field of the record data, and replace the field data in the row of record information according to the preset correspondence; refer to the above description, and will not be repeated here.

[0093] The preset correspondence includes the correspondence between preset field data types and preset replacement character content; please refer to the above description, and it will not be repeated here.

[0094] Each replacement generates a new record, yielding test data corresponding to data types that do not match the stated field data type. Refer to the above explanation; further details are omitted.

[0095] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0096] Furthermore, the field data types include numeric fields, character fields, and date fields; correspondingly, replacing the field data in the row of record information according to the preset correspondence includes:

[0097] The step of replacing the numeric, character, and date fields in a row of record information according to a preset correspondence can be referred to the above description and will not be repeated here.

[0098] The preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content. Refer to the above description; further details are omitted.

[0099] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0100] Furthermore, the interface document attributes include a non-primary key field identifier, and the abnormal test data type includes fields defined as not allowing null values ​​but with null data; correspondingly, generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes:

[0101] Insert a row of data into the data table that has the same data content as all fields of the original record data. Then, based on the non-primary key field identifier, clear the data of the non-primary key fields in the original row of data to obtain test data corresponding to the field definition that does not allow null values ​​and whose data is empty. Refer to the above explanation; further details are omitted.

[0102] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0103] Furthermore, the interface document attributes include the field corresponding to the file to be loaded, and the abnormal test data type includes excessively long data; correspondingly, generating test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data includes:

[0104] If the field is determined to be a delimiter field or a fixed-length field, then insert a row of records in the data table with the same content as the data in each field of the record data, and add one digit after the data corresponding to the delimiter field or the fixed-length field to obtain the test data corresponding to the excessively long data. Refer to the above explanation; further details are omitted.

[0105] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0106] Furthermore, after the step of generating test data corresponding to the exception test data type in the data table based on the interface document attributes and the record data, the method for generating test data further includes:

[0107] All test data are packaged together to obtain a test data file. Refer to the above instructions; further details are omitted.

[0108] The method for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition by summarizing the data.

[0109] It should be noted that the method for generating test data provided in this embodiment of the invention can be used in the financial field, or in any technical field other than the financial field. This embodiment of the invention does not limit the application field of the method for generating test data.

[0110] Figure 4 This is a schematic diagram of the structure of a device for generating test data according to an embodiment of the present invention, as shown below. Figure 4 As shown, the apparatus for generating test data provided in this embodiment of the invention includes an acquisition unit 401, a first generation unit 402, and a second generation unit 403, wherein:

[0111] The acquisition unit 401 is used to acquire the header fields of the file to be loaded and create a data table with the same header fields; the data table is empty except for the header fields; the first generation unit 402 is used to generate record data in the data table as baseline data according to the interface document attributes of the file to be loaded; the second generation unit 403 is used to generate test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data.

[0112] Specifically, the acquisition unit 401 in the device is used to acquire the header fields of the file to be loaded and create a data table with the same header fields; the data table is empty except for the header fields; the first generation unit 402 is used to generate record data in the data table as baseline data according to the interface document attributes of the file to be loaded; the second generation unit 403 is used to generate test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data.

[0113] The apparatus for generating test data provided in this embodiment of the invention obtains the header fields of the file to be loaded and creates a data table with the same header fields; the data table is empty except for the header fields; record data is generated in the data table as baseline data according to the interface document attributes of the file to be loaded; test data corresponding to the abnormal test data type is generated in the data table according to the interface document attributes and the record data, which can improve the efficiency of test data acquisition.

[0114] Furthermore, the interface document attributes include a primary key field identifier, and the abnormal test data type includes duplicate primary keys; correspondingly, the second generation unit 403 is specifically used for:

[0115] Insert a row of record information in the data table that has the same data content as each field of the record data, and obtain test data corresponding to the duplication of the data primary key based on the primary key field identifier.

[0116] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0117] Furthermore, the interface document attributes include a preset correspondence, and the abnormal test data type includes field data type mismatch; correspondingly, the second generation unit 403 is specifically used for:

[0118] Insert a row of record information that has the same data content as each field of the record data into the data table, and replace the field data in the row of record information according to the preset correspondence;

[0119] The preset correspondence includes the correspondence between preset field data types and preset replacement character content;

[0120] Each replacement generates a new row of record information, resulting in test data that does not match the data type of the field.

[0121] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0122] Furthermore, the field data types include numeric fields, character fields, and date fields; correspondingly, the second generation unit 403 is also specifically used for:

[0123] The numeric, character, and date fields in a row of record information are replaced according to a preset correspondence.

[0124] The preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content.

[0125] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0126] Furthermore, the interface document attributes include a non-primary key field identifier, and the exception test data type includes fields defined as not allowing null values ​​but with empty data; correspondingly, the second generation unit 403 is specifically used for:

[0127] Insert a row of record information with the same data content as each field of the record data into the data table, and clear the data of the non-primary key fields in the row of record information according to the non-primary key field identifier to obtain test data corresponding to the field definition that does not allow null and the data is empty.

[0128] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0129] Furthermore, the interface document attributes include the field corresponding to the file to be loaded, and the abnormal test data type includes excessively long data; correspondingly, the second generation unit 403 is specifically used for:

[0130] If the field is determined to be a delimiter field or a fixed-length field, then insert a row of record information in the data table that has the same data content as each field of the record data, and add 1 digit of data after the data corresponding to the delimiter field or the fixed-length field to obtain test data corresponding to the excessively long data.

[0131] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition.

[0132] Furthermore, after the step of generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data, the apparatus for generating test data is further configured to:

[0133] Various test data are packaged together to obtain a test data file.

[0134] The apparatus for generating test data provided in this embodiment of the invention can further improve the efficiency of test data acquisition by summarizing the data.

[0135] The embodiments of the present invention provide an apparatus for generating test data that can be used to execute the processing flow of the above-described method embodiments. Its functions will not be repeated here, but can be referred to the detailed description of the above-described method embodiments.

[0136] Figure 5 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as... Figure 5 As shown, the electronic device includes: a processor 501, a memory 502, and a bus 503;

[0137] The processor 501 and the memory 502 communicate with each other via the bus 503.

[0138] The processor 501 is used to call program instructions in the memory 502 to execute the methods provided in the above-described method embodiments, including, for example:

[0139] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0140] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0141] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0142] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can perform the methods provided in the above-described method embodiments, such as:

[0143] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0144] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0145] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0146] This embodiment provides a computer-readable storage medium storing a computer program that causes the computer to execute the methods provided in the above-described method embodiments, including, for example:

[0147] Obtain the header fields of the file to be loaded, and create a data table with the same header fields; the data table is empty except for the header fields.

[0148] Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data.

[0149] Based on the interface document attributes and the record data, test data corresponding to the exception test data type is generated in the data table.

[0150] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0151] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0152] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0153] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0154] In the description of this specification, the references to terms such as "an embodiment," "a specific embodiment," "some embodiments," "for example," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0155] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for generating test data, characterized in that, include: Obtain the header fields of the file to be loaded, and create a data table with the same header fields. The data table is empty except for the header field; Based on the interface document attributes of the file to be loaded, generate record data in the data table to serve as baseline data. Based on the interface document attributes and the record data, test data corresponding to the abnormal test data type is generated in the data table; The interface document attributes include a primary key field identifier, and correspondingly, the abnormal test data type includes duplicate primary keys; the interface document attributes also include a preset correspondence, and correspondingly, the abnormal test data type includes mismatched field data types; the interface document attributes also include a non-primary key field identifier, and correspondingly, the abnormal test data type includes a field definition that does not allow null values ​​but the data is empty; the interface document attributes also include the field to which the file to be loaded belongs, and correspondingly, the abnormal test data type includes excessively long data. The step of generating test data corresponding to the abnormal test data type in the data table based on the interface document attributes and the record data includes: Insert a row of record information in the data table that has the same data content as each field of the record data, and obtain test data corresponding to the duplication of the data primary key based on the primary key field identifier; Insert a row of record information with the same data content as each field of the record data into the data table, and replace the numeric field, character field and date field in the row of record information according to the preset correspondence; The field data types include numeric fields, character fields, and date fields; the preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content. Each replacement generates a new row of record information, obtaining test data that does not match the data type of the field. Insert a row of record information with the same data content as each field of the record data into the data table, and clear the data of the non-primary key fields in the row of record information according to the non-primary key field identifier to obtain test data corresponding to the field definition that does not allow null and the data is empty; If the field is determined to be a delimiter field or a fixed-length field, then insert a row of record information in the data table that has the same data content as each field of the record data, and add 1 digit of data after the data corresponding to the delimiter field or the fixed-length field to obtain test data corresponding to the excessively long data.

2. The method for generating test data according to claim 1, characterized in that, After the step of generating test data corresponding to the exception test data type in the data table based on the interface document attributes and the record data, the method for generating test data further includes: Various test data are packaged together to obtain a test data file.

3. An apparatus for generating test data, characterized in that, include: The acquisition unit is used to acquire the header fields of the file to be loaded and create a data table with the same header fields. The data table is empty except for the header field; The first generation unit is used to generate record data in the data table as reference data according to the interface document attributes of the file to be loaded. The second generation unit is used to generate test data corresponding to the abnormal test data type in the data table according to the interface document attributes and the record data. The interface document attributes include a primary key field identifier, and correspondingly, the abnormal test data type includes duplicate primary keys; the interface document attributes also include a preset correspondence, and correspondingly, the abnormal test data type includes mismatched field data types; the interface document attributes also include a non-primary key field identifier, and correspondingly, the abnormal test data type includes a field definition that does not allow null values ​​but the data is empty; the interface document attributes also include the field to which the file to be loaded belongs, and correspondingly, the abnormal test data type includes excessively long data. The second generation unit is specifically used for: Insert a row of record information in the data table that has the same data content as each field of the record data, and obtain test data corresponding to the duplication of the data primary key based on the primary key field identifier; Insert a row of record information with the same data content as each field of the record data into the data table, and replace the numeric field, character field and date field in the row of record information according to the preset correspondence; The field data types include numeric fields, character fields, and date fields; the preset correspondence includes a first correspondence between a preset numeric field and a preset first replacement character content, a second correspondence between a preset character field and a preset second replacement character content, and a third correspondence between a preset date field and a preset third replacement character content. Each replacement generates a new row of record information, obtaining test data that does not match the data type of the field. Insert a row of record information with the same data content as each field of the record data into the data table, and clear the data of the non-primary key fields in the row of record information according to the non-primary key field identifier to obtain test data corresponding to the field definition that does not allow null and the data is empty; If the field is determined to be a delimiter field or a fixed-length field, then insert a row of record information in the data table that has the same data content as each field of the record data, and add 1 digit of data after the data corresponding to the delimiter field or the fixed-length field to obtain test data corresponding to the excessively long data.

4. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 2.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 2.