Automatic test data generation method and device, terminal and medium
By obtaining and parsing the original test data template and data differentiated information, differentiated test data templates are generated, and the problems of low efficiency and error-prone testing data processing in the existing technology are solved, and automated test data generation is realized, which improves the quality and efficiency of testing work.
Patent Information
- Application Number
- CN202411704547.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-04
AI Technical Summary
Existing test data processing methods are inefficient and error-prone, especially when multiple data types are involved, testers need to manually adjust parameters, resulting in inefficiency and high error rates.
By obtaining the original test data template and data differentiation information, performing field analysis and matching, generating differentiated test data templates, and achieving automatic automatic generation of test data.
It improves the efficiency and accuracy of test data generation, reduces human errors, can effectively meet a variety of data modification needs, and improves the quality and efficiency of test work.
Smart Images

Figure CN119557222A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, terminal and medium for automatically generating test data. Background Art
[0002] In the field of software development and testing, generating test data is a key link that directly affects the quality and efficiency of software testing.
[0003] For specific testing needs, interface requests usually involve a large number of parameters that need to be compressed and included in a single request. This not only means a huge number of parameters, but also requires support for multiple parameter types. This complexity poses a difficult challenge to testers.
[0004] In traditional practices, when the data involved are of many types, testers often need to manually adjust parameters to meet different quantity requirements and make multiple copies for testing, which is not only inefficient but also prone to errors. Summary of the invention
[0005] The present application provides a method, device, terminal and medium for automatically generating test data, which are used to solve the technical problems of low efficiency and easy errors in existing test data processing methods.
[0006] In order to solve the above technical problems, the first aspect of the present application provides a method for automatically generating test data, comprising:
[0007] Acquire an original test data template and data differentiation information, wherein the data differentiation information includes one or more data field names and one or more data field values associated with the data field names;
[0008] Performing field parsing according to the original test data template to identify template field names in the original test data template and template field values corresponding to each template field name;
[0009] Determine the target field name according to the matching of the template field name and the data field name, and determine the target field value from the data field value corresponding to the target field name;
[0010] The corresponding template field value is replaced according to the target field value to obtain a differentiated test data template.
[0011] Preferably, the data differentiation information also includes: a data difference amount threshold, which is used to control the number of types of the differentiated test data template output, wherein there is at least one different field pair between different types of differentiated test data templates and between each differentiated test data template and the original test data template.
[0012] Preferably, determining the target field value from the data field value corresponding to the target field name comprises:
[0013] When there are multiple data field values corresponding to the target field name, several different data field values are randomly or sequentially extracted from the data field values as target field values according to the data difference threshold, so as to output several differentiated test data templates according to the target field values.
[0014] Preferably, the data difference threshold includes: a template difference threshold and / or a field difference threshold.
[0015] Preferably, it also includes:
[0016] When there is no corresponding data field name in the template field name, a target field name corresponding to the data field name is added, and a target field value corresponding to the target field name is determined.
[0017] Preferably, after obtaining the original test data template and the data differentiation information, the method further includes:
[0018] The original test data template and the data differentiation information are encrypted by a preset encryption algorithm to obtain a key sequence;
[0019] According to the historical synthesis template database, the key sequence is used as a key value to match the data in the historical synthesis template database, and if the match is successful, the differential test data template corresponding to the key sequence is extracted from the historical synthesis template database;
[0020] When no match is successful, the process jumps to field parsing according to the original test data template, and after obtaining each differentiated test data template generated based on the original test data and the data differentiation information, the each differentiated test data template is associated with the key sequence and then stored in the historical synthetic template database.
[0021] Preferably, the encrypting the original test data and the data differentiation information by a preset encryption algorithm to obtain a key sequence specifically includes:
[0022] The original test data template and the data differentiation information are encrypted respectively by a preset encryption algorithm to obtain a template key sequence and an input parameter key sequence;
[0023] The template key sequence and the input key sequence are concatenated to obtain a key sequence.
[0024] A second aspect of the present application provides a test data automatic generation device, comprising:
[0025] A data acquisition unit, used to acquire an original test data template and data differentiation information, wherein the data differentiation information includes one or more data field names and one or more data field values associated with the data field names;
[0026] A template parsing unit, configured to perform field parsing according to the original test data template to identify template field names in the original test data template and template field values corresponding to each template field name;
[0027] A field matching unit, used to determine a target field name according to a match between the template field name and the data field name, and determine a target field value from the data field value corresponding to the target field name;
[0028] The differential template generating unit is used to replace the corresponding template field value according to the target field value to obtain a differential test data template.
[0029] A third aspect of the present application provides a test data automatic generation terminal, comprising: a memory and a processor;
[0030] The memory is used to store program codes, and the program codes correspond to a method for automatically generating test data as provided in the first aspect of the present application;
[0031] The processor is used for reading and executing the program code.
[0032] The fourth aspect of the present application provides a computer-readable storage medium, in which a program code is stored. The program code is used to be read and executed by a processor to implement a method for automatically generating test data as provided in the first aspect of the present application.
[0033] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0034] The solution provided by the present application first obtains the original test data template and data differentiation information, wherein the data differentiation information contains the data field name used to generate the differentiation template and one or more data field values associated with the data field name, and then performs field parsing on the original test data template to identify the field name in the original template and the corresponding field value, and then matches the field name in the data differentiation information with the identified field name to determine one or more target field names that need to be differentiated, and determines the corresponding target field value according to the association relationship contained in the data differentiation information, and then replaces the corresponding template field value according to the target field value, so as to obtain a differentiated test data template with the same format as the original test data template but different content, thereby realizing automatic generation of test data for multiple data modification requirements and improving the quality and efficiency of testing work. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0036] Figure 1 A flowchart of an embodiment of a method for automatically generating test data provided in the present application.
[0037] Figure 2 A flowchart of another embodiment of a method for automatically generating test data provided by the present application.
[0038] Figure 3 This is an overall process logic diagram of a test data automatic generation method provided in this application.
[0039] Figure 4 A schematic diagram of the structure of an embodiment of a test data automatic generation device provided in the present application.
[0040] Figure 5 A schematic diagram of the structure of an embodiment of a test data automatic generation terminal provided in the present application. DETAILED DESCRIPTION
[0041] The embodiments of the present application provide a method, device, terminal and medium for automatically generating test data, which are used to solve the technical problems that the existing test data processing methods are inefficient and prone to errors.
[0042] In order to make the purpose, features, and advantages of the invention of this application more obvious and easy to understand, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the embodiments described below are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] First, a detailed description of an embodiment of a method for automatically generating test data provided by the present application is as follows:
[0044] See also Figure 1 , this embodiment provides a method for automatically generating test data, including:
[0045] Step 101: Obtaining an original test data template and data differentiation information;
[0046] The data differentiation information includes one or more data field names and one or more data field values associated with the data field names;
[0047] Step 102: Perform field parsing according to the original test data template to identify template field names in the original test data template and template field values corresponding to each template field name;
[0048] Step 103: Determine the target field name based on the matching between the template field name and the data field name, and determine the target field value from the data field value corresponding to the target field name;
[0049] Step 104: Replace the corresponding template field value according to the target field value to obtain a differentiated test data template.
[0050] It should be noted that according to the method provided in this embodiment, first, the original test data template and data differentiation information are obtained, wherein the original test data template is a blueprint for generating a differentiated test data template, and generally a data template in JSON format can be used, and the data differentiation information contains the field data required for differentiated processing of the original test data template, including: one or more field names and the field values corresponding to each field name, thereby generating a differentiated test data template that is different from the original test data template.
[0051] Then, the original test data template is parsed to identify the template field names contained in the original test data template and the template field values corresponding to each template field name, thereby obtaining multiple sets of<X,Y> The template field pair information of the structure, where X represents the field name, such as "ID", "address", etc., and Y represents the field value corresponding to the field name.
[0052] Next, according to the data field pair information in the data differentiation information, the field name information therein is used to match the template field pair information to determine the target field name and its file location that need to be differentiated. Then, according to the target field value corresponding to the target field name, the corresponding template field value is replaced according to the target field value to obtain the differentiated test data template;
[0053] For example, if the field pair information in the original template is {k1:v1, k2:v2, k3:v3}, where k represents the field name and v represents the field value, and then the data field pair information {k1:v4, k3:v5} is recorded in the data differentiation information, that is, the k1 and k3 fields are the target field names. At this time, after processing according to this embodiment, the following new templates can be generated: {k1:v4, k2:v2, k3:v5}, {k1:v1, k2:v2, k3:v5} and {k1:v4, k2:v2, k3:v3}, that is, differentiated test data templates.
[0054] Based on the above method embodiment, the test data automatic generation method provided by the present application may also include the following contents:
[0055] Further, determining the target field value from the data field value corresponding to the target field name includes:
[0056] When there are multiple data field values corresponding to the target field name, several different data field values are randomly or sequentially extracted from the data field values as target field values according to the data difference threshold, so as to output several differentiated test data templates according to the target field values.
[0057] It should be noted that, for example, taking the field pair information {k1:v1, k2:v2, k3:v3} in the above-mentioned original template as an example, when the data differentiation information of this embodiment records the situation where a field name corresponds to multiple field values, the expression of this type of data field pair information includes but is not limited to: {k1:v4 / v5} or {k1:v4, k1:v5}, etc. At this time, after processing according to this embodiment, the following new templates can be generated: {k1:v4, k2:v2, k3:v3} and {k1:v5, k2:v2, k3:v3}, thereby realizing the automatic generation of test data with multiple data modification requirements and improving the quality and efficiency of testing work.
[0058] In some embodiments, the data differentiation information also includes: a data difference amount threshold, which is used to control the number of types of differentiated test data template outputs, wherein there is at least one different field pair between different types of differentiated test data templates and between each differentiated test data template and the original test data template. If all field pairs of any two templates are the same, then the two templates can be regarded as templates of the same type.
[0059] It should be noted that the data differentiation information mentioned above may further include: a data difference amount threshold value, which is used to control the number of types of differentiated test data template outputs. Before the method is implemented, the value of the data difference amount threshold value may be configured first, and when the method is implemented, according to the data difference amount threshold value, several differentiated test data templates that meet the threshold constraint requirements are generated.
[0060] Furthermore, the data difference threshold includes: a template difference threshold and / or a field difference threshold, wherein the template difference threshold is used to control the number of types of differentiated test data templates, that is, to control how many types of differentiated test data templates are to be output at least; for example, taking the original test data template with field pair information {k1:v1, k2:v2, k3:v3} and the data differentiation information of {k1:v4, k3:v5} as an example, when the template difference threshold is set to 2, then when any two of {k1:v4, k2:v2, k3:v5}, {k1:v1, k2:v2, k3:v5} and {k1:v4, k2:v2, k3:v3} are output, it can be determined that the differentiated test data template generation task is completed.
[0061] The field difference threshold is used to differentiate the number of types of some fields in the test data template, that is, to control the number of differences of a certain field in the output differentiated test data template. For example, taking the original test data template with field pair information {k1:v1, k2:v2, k3:v3} and the data differentiation information {k1:v4 / v5 / v6} as an example, when the field difference threshold is set for field k1, and the field difference threshold is set to 2, when any two of {k1:v4, k2:v2, k3:v3}, {k1:v5, k2:v2, k3:v3} and {k1:v6, k2:v2, k3:v3} are generated, it can be determined that the generation task of the differentiated test data template has been completed.
[0062] It can be understood that the template difference threshold and field difference threshold mentioned above can be set at the same time. When both thresholds are set, when the number of types of differentiated test data templates generated can simultaneously meet the above two threshold conditions, it can be determined that the differentiated test data template generation task has been completed.
[0063] Furthermore, in the process of determining the target field name according to the matching of the template field name and the data field name in step 103, the following steps may be further included:
[0064] Step 1031: When there is no corresponding data field name in the template field name, a target field name corresponding to the data field name is added, and a target field value corresponding to the target field name is determined.
[0065] For example, taking the field pair information {k1:v1, k2:v2, k3:v3} in the original template as an example, when the data field pair information {k4:v6} is recorded in the data differentiation information, since the k4 field does not exist in the original template, the k4 field can be added in a new manner according to step 1031, so that a differentiated test data template containing the k4 field can be generated subsequently.
[0066] It can be understood that the types of fields mentioned in this embodiment may include common types such as integers, strings, arrays, etc. Among them, for the fields recorded in the data differentiation information, when the field value of a data field name is numeric data, its field value can be configured in the form of a constant, and can also be configured in the form of a value range and / or assignment formula.
[0067] Furthermore, if Figure 2 and Figure 3 As shown, after obtaining the original test data template and data differentiation information, the following steps are also included:
[0068] Step 1011: encrypt the original test data template and data differentiation information using a preset encryption algorithm to obtain a key sequence;
[0069] Step 1012: According to the historical synthetic template database, the key sequence is used as the key value to match the data in the historical synthetic template database. If the match is successful, the differentiated test data template corresponding to the key sequence is extracted from the historical synthetic template database. If the match is not successful, jump to step 102, and after obtaining each differentiated test data template generated based on the original test data and data differentiation information, each differentiated test data template is associated with the key sequence and then stored in the historical synthetic template database.
[0070] It should be noted that the present embodiment can also encrypt the acquired original test data template and data differentiation information through a preset encryption algorithm, such as the MD5 encryption algorithm, the SM2 encryption algorithm, etc., to obtain a corresponding key sequence, and use the key sequence to match the data in the historical synthesis template database to determine whether previous tasks have generated test data with the same requirements. If the match is successful, the required test data can be directly read from the database and returned without the need to regenerate it, thereby reducing resource consumption. Otherwise, according to the process of steps 102 to 104 above, sufficient differentiated test data templates are generated and stored in the historical synthesis template database for future task calls.
[0071] More specifically, the step 1001 above encrypts the original test data and the data differentiation information using a preset encryption algorithm to obtain a key sequence, and this step may further include:
[0072] The original test data template and data differentiation information are encrypted respectively through a preset encryption algorithm to obtain a template key sequence and an input parameter key sequence;
[0073] Concatenate the template key sequence and the input key sequence to obtain the key sequence.
[0074] The scheme provided by the present embodiment uses the template uploaded by the user as the basic input, and the system can intelligently generate various types of template data according to its structure and content. These generated template data not only maintain a certain relevance and consistency with the template uploaded by the user in data structure and format, but also increase its diversity by changing and expanding according to the processing method of this application. After generating various types of templates, the system efficiently transmits them to the back end. Such a design greatly improves the efficiency of data generation, because the back end can directly use these diverse templates for subsequent data processing and application, without the need to carry out cumbersome template creation and configuration work. At the same time, the generation of various types of templates also provides strong support for the diversification of data, enriches the types and forms of test data, makes the test scenario more comprehensive and real, thereby effectively improving the quality and reliability of the test.
[0075] The above is a detailed description of an embodiment of a method for automatically generating test data provided by the present application. The following is a detailed description of an embodiment of an apparatus for automatically generating test data provided by the present application.
[0076] See also Figure 4 , an automatic test data generation device provided in an embodiment of the present application includes:
[0077] The data acquisition unit 201 is used to acquire the original test data template and data differentiation information, wherein the data differentiation information includes one or more data field names and one or more data field values associated with the data field names;
[0078] The template parsing unit 202 is used to perform field parsing according to the original test data template to identify the template field names in the original test data template and the template field values corresponding to the template field names;
[0079] A field matching unit 203, used to determine a target field name according to the matching between the template field name and the data field name, and to determine a target field value from the data field value corresponding to the target field name;
[0080] The differential template generating unit 204 is used to replace the corresponding template field value according to the target field value to obtain a differential test data template.
[0081] In addition to the above-mentioned virtual device embodiments, the present application also provides specific descriptions of corresponding terminal and computer-readable storage medium embodiments.
[0082] like Figure 5 As shown, the embodiment of the present application provides a test data automatic generation terminal, the implementation types of the terminal include but are not limited to: personal computers, industrial computers, servers and embedded intelligent devices, the main components of the terminal include: a memory 33 and a processor 31, wherein the memory 33 and the processor 31 can be connected via a communication bus 34;
[0083] The memory 33 is used to store program codes, and the program codes correspond to a test data automatic generation method mentioned in the above embodiment;
[0084] The processor 31 is used to read and execute program codes.
[0085] A fourth aspect of the present application provides a computer-readable storage medium, in which a program code is stored. The program code is used to be read and executed by a processor to implement a method for automatically generating test data as mentioned in the above embodiment.
[0086] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the terminals, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0087] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0088] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0089] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0090] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0091] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0092] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0093] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for automatically generating test data, characterized in that: include: Acquire an original test data template and data differentiation information, wherein the data differentiation information includes one or more data field names and one or more data field values associated with the data field names; Performing field parsing according to the original test data template to identify template field names in the original test data template and template field values corresponding to each template field name; Determine the target field name according to the matching of the template field name and the data field name, and determine the target field value from the data field value corresponding to the target field name; The corresponding template field value is replaced according to the target field value to obtain a differentiated test data template.
2. A method for automatically generating test data according to claim 1, characterized in that: The data differentiation information also includes: a data difference amount threshold, which is used to control the number of types of the differentiated test data template output, wherein there is at least one different field pair between different types of differentiated test data templates and between each differentiated test data template and the original test data template.
3. A method for automatically generating test data according to claim 2, characterized in that: Determining the target field value from the data field value corresponding to the target field name includes: When there are multiple data field values corresponding to the target field name, several different data field values are randomly or sequentially extracted from the data field values as target field values according to the data difference threshold, so as to output several differentiated test data templates according to the target field values.
4. A method for automatically generating test data according to claim 2, characterized in that: The data difference threshold includes: a template difference threshold and / or a field difference threshold.
5. The method for automatically generating test data according to claim 1, characterized in that: Also includes: When there is no corresponding data field name in the template field name, a target field name corresponding to the data field name is added, and a target field value corresponding to the target field name is determined.
6. A method for automatically generating test data according to claim 1, characterized in that: After obtaining the original test data template and the data differentiation information, the method further includes: The original test data template and the data differentiation information are encrypted by a preset encryption algorithm to obtain a key sequence; According to the historical synthesis template database, the key sequence is used as a key value to match the data in the historical synthesis template database, and if the match is successful, the differential test data template corresponding to the key sequence is extracted from the historical synthesis template database; When no match is successful, the process jumps to field parsing according to the original test data template, and after obtaining each differentiated test data template generated based on the original test data and the data differentiation information, the each differentiated test data template is associated with the key sequence and then stored in the historical synthetic template database.
7. A method for automatically generating test data according to claim 6, characterized in that: The method of encrypting the original test data and the data differentiation information by a preset encryption algorithm to obtain a key sequence specifically includes: The original test data template and the data differentiation information are encrypted respectively by a preset encryption algorithm to obtain a template key sequence and an input parameter key sequence; The template key sequence and the input key sequence are concatenated to obtain a key sequence.
8. A device for automatically generating test data, characterized in that: include: A data acquisition unit, used to acquire an original test data template and data differentiation information, wherein the data differentiation information includes one or more data field names and one or more data field values associated with the data field names; A template parsing unit, configured to perform field parsing according to the original test data template to identify template field names in the original test data template and template field values corresponding to each template field name; A field matching unit, used to determine a target field name according to a match between the template field name and the data field name, and determine a target field value from data field values corresponding to the target field name; The differential template generating unit is used to replace the corresponding template field value according to the target field value to obtain a differential test data template.
9. A test data automatic generation terminal, characterized in that: include: Memory and processor; The memory is used to store program codes, and the program codes correspond to a method for automatically generating test data according to any one of claims 1 to 7; The processor is used for reading and executing the program code.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, and the program code is used to be read and executed by a processor to implement a method for automatically generating test data as described in any one of claims 1 to 7.