CN-115904990-B - Method and device for generating test data
Abstract
The invention provides a method and a device for generating test data, relates to the technical field of testing, and can be used in the financial field or other technical fields. The method comprises the steps of obtaining a header field of a file to be loaded, creating a data table identical to the header field, wherein data except the header field of the data table is empty, generating record data serving as reference data in the data table according to an interface document attribute of the file to be loaded, 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 apparatus performs the above method. The method and the device for generating the test data can improve the working efficiency of test data acquisition.
Inventors
- TAN GUIXING
- GUO HUA
- ZHU WUPING
Assignees
- 中国工商银行股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20221206
Claims (5)
- 1. A method of generating test data, comprising: acquiring a header field of a file to be loaded, and creating a data table identical to the header field, wherein data except the header field of the data table is empty; generating record data serving as reference data in the data table according to the interface document attribute of the file to be loaded; Generating test data corresponding to the abnormal test data type in the data table according to the interface document attribute and the record data; The interface document attribute comprises a primary key field identifier, and the abnormal test data type comprises data primary key repetition; the interface document attribute further comprises a preset corresponding relation, and correspondingly, the abnormal test data type further comprises a field data type disagreement, the interface document attribute further comprises a non-primary key field identifier, correspondingly, the abnormal test data type further comprises a field definition disallowing null and the data is null; the generating test data corresponding to the abnormal test data type in the data table according to the interface document attribute and the record data comprises the following steps: inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and obtaining test data corresponding to the data primary key repetition according to the primary key field identification; inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and respectively replacing a digital field, a character field and a date field in the one-line record information according to a preset corresponding relation; the preset corresponding relation comprises a first corresponding relation between a preset digital field and preset first replacement character content, a second corresponding relation between a preset character field and preset second replacement character content and a third corresponding relation between a preset date field and preset third replacement character content; generating a new line of record information once for each replacement to obtain test data corresponding to the field data type disagreement; Inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and clearing the data of the non-primary key field in the one-line record information according to the non-primary key field identification to obtain test data corresponding to the field definition not allowing blank and the data being blank; If the field is determined to be a separator field or a fixed-length field, inserting a piece of one line of record information with the same data content as each field of the record data into the data table, and adding 1-bit data after the data corresponding to the separator field or the fixed-length field to obtain test data corresponding to the ultralong data.
- 2. The method of generating test data according to claim 1, wherein after the step of generating test data corresponding to an abnormal test data type in the data table based on the interface document attribute and the record data, the method of generating test data further comprises: And uniformly packaging various test data to obtain a test data file.
- 3. An apparatus for generating test data, comprising: the file loading device comprises an acquisition unit, a data table and a loading unit, wherein the acquisition unit is used for acquiring a header field of a file to be loaded and creating a data table which is the same as the header field; A first generating unit configured to generate record data serving as reference data in the data table according to the interface document attribute of the file to be loaded; a second generating unit, configured to generate test data corresponding to an abnormal test data type in the data table according to the interface document attribute and the record data; The interface document attribute comprises a primary key field identifier, and the abnormal test data type comprises data primary key repetition; the interface document attribute further comprises a preset corresponding relation, and correspondingly, the abnormal test data type further comprises a field data type disagreement, the interface document attribute further comprises a non-primary key field identifier, correspondingly, the abnormal test data type further comprises a field definition disallowing null and the data is null; The second generating unit is specifically configured to: inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and obtaining test data corresponding to the data primary key repetition according to the primary key field identification; inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and respectively replacing a digital field, a character field and a date field in the one-line record information according to a preset corresponding relation; the preset corresponding relation comprises a first corresponding relation between a preset digital field and preset first replacement character content, a second corresponding relation between a preset character field and preset second replacement character content and a third corresponding relation between a preset date field and preset third replacement character content; generating a new line of record information once for each replacement to obtain test data corresponding to the field data type disagreement; Inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and clearing the data of the non-primary key field in the one-line record information according to the non-primary key field identification to obtain test data corresponding to the field definition not allowing blank and the data being blank; If the field is determined to be a separator field or a fixed-length field, inserting a piece of one line of record information with the same data content as each field of the record data into the data table, and adding 1-bit data after the data corresponding to the separator field or the fixed-length field to obtain test data corresponding to the ultralong data.
- 4. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method of any one of claims 1 to 2 when the computer program is executed by the processor.
- 5. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1 to 2.
Description
Method and device for generating test data Technical Field The invention relates to the technical field of testing, in particular to a method and a device for generating test data. Background At present, whether an ORACLE database is used or a domestic Gaussian database is switched, the file loading function has extremely high data quality requirements on texts, if the conditions of repeated data primary keys, inconsistent types, inadmissible field definitions, empty data, long and short data and the like are likely to cause interruption of data import, generally, as a downstream system for receiving files, a public program is specially written to carry out compatible processing on the abnormal data so as to avoid interruption, and as a tester of a file receiver, a tester obviously feels that two urgent pain points to be solved are that 1, the tester needs to spend quite much time for manually filling text against an interface structure, and 2, the test data of the conditions of repeated manual number simulation primary keys, inadmissible types, inadmissible field definitions, empty data, long and short data and the like are frequently missed. Disclosure of Invention Aiming at the problems in the prior art, the embodiment of the invention provides a method and a device for generating test data, which can at least partially solve the problems in the prior art. In one aspect, the present invention provides a method for generating test data, including: acquiring a header field of a file to be loaded, and creating a data table identical to the header field, wherein data except the header field of the data table is empty; generating record data serving as reference data in the data table according to the interface document attribute of the file to be loaded; and generating test data corresponding to the abnormal test data type in the data table according to the interface document attribute and the record data. The interface file attribute comprises a main key field identifier, the abnormal test data type comprises data main key repetition, and correspondingly, the test data corresponding to the abnormal test data type is generated in the data table according to the interface file attribute and the record data, and the method comprises the following steps: And inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and obtaining test data corresponding to the data primary key repetition according to the primary key field identification. The interface file attribute comprises a preset corresponding relation, the abnormal test data type comprises a field data type disagreement, and correspondingly, the test data corresponding to the abnormal test data type is generated in the data table according to the interface file attribute and the record data, and the method comprises the following steps: Inserting a piece of one-line record information with the same content as each field of the record data into the data table, and replacing the field data in the one-line record information according to the preset corresponding relation; The preset corresponding relation comprises a corresponding relation between a preset field data type and preset replacement character content; And generating a new line of record information every time of replacement to obtain test data corresponding to the field data type disagreement. The field data type comprises a digital field, a character field and a date field, and correspondingly, the replacing the field data in the line of record information according to the preset corresponding relation comprises the following steps: Respectively replacing a digital field, a character field and a date field in the row of record information according to a preset corresponding relation; The preset corresponding relation comprises a first corresponding relation between a preset digital field and preset first replacement character content, a second corresponding relation between a preset character type field and preset second replacement character content and a third corresponding relation between a preset date type field and preset third replacement character content. The interface file attribute comprises a non-primary key field identifier, the abnormal test data type comprises a field definition which is not allowed to be empty and data is empty, and correspondingly, the test data corresponding to the abnormal test data type is generated in the data table according to the interface file attribute and the record data, and the method comprises the following steps: and inserting a piece of one-line record information with the same data content as each field of the record data into the data table, and clearing the data of the non-primary key field in the one-line record information according to the non-primary key field identification to obtain test data corresponding to the field definition not allowing blank and the data being bl