Test data generation method and device, electronic equipment and medium

By automatically generating and storing test data, the problem of inefficient unit testing in the existing technology is solved, efficient and accurate unit testing is achieved, and it is suitable for testing scenarios of complex structures.

CN118939545APending Publication Date: 2024-11-12CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410989377.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

In the prior art, the test data of unit tests is mainly written manually by developers, which is inefficient and difficult to cover all potential problems. Especially in the case of complex nested classes and structures, it is prone to errors and reduces the efficiency of unit tests.

Method used

By automatically generating test data, obtaining the pending structure in the target database, serializing it, generating test data and storing it to the database, using pressure testing tools to simulate real scenes, setting breakpoints and configuration files to automatically call serialization functions, and implementing Non-invasive test data generation.

Benefits of technology

It improves the efficiency of unit testing, reduces workload, reduces human errors, can effectively cover potential problems in complex structures, and improves the accuracy and efficiency of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939545A_ABST
    Figure CN118939545A_ABST
Patent Text Reader

Abstract

The invention provides a test data generation method and device, electronic equipment and a medium, and relates to the technical field of computers.The method comprises the steps that a to-be-processed structural body in a target database is obtained; according to the method, the to-be-processed structural body is subjected to serialization processing to obtain the test data of the to-be-processed structural body subjected to serialization processing, and the test data is stored in the target database, so that the test data is automatically generated and stored in the database to be used by all subsequent unit tests, the workload of unit tests is reduced, and the test efficiency is improved. Therefore, the efficiency of unit testing is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a test data generating method, device, electronic device and medium. Background Art

[0002] Software testing is the process of executing a program to find errors, and is a key step in software quality assurance. According to the development stage, software testing can be divided into unit testing, integration testing, system testing, and acceptance testing. Unit testing refers to the inspection and verification of the smallest testable unit in the software. The unit can be a function or a functional module.

[0003] At present, unit tests in related technologies are all manually written by developers with test data. This method is not only inefficient and difficult to cover all potential problems, but also as the amount of project code grows (especially when there are complex nested classes and structures), manually setting test data will make unit testing time-consuming and error-prone, thereby reducing the efficiency of unit testing. Summary of the invention

[0004] The present invention provides a test data generation method, device, electronic device and medium to solve the problems in the related art. The test data is automatically generated and stored in a database for use in all subsequent unit tests, thereby reducing the workload of unit testing and improving the efficiency of unit testing.

[0005] A first aspect of the present disclosure provides a test data generation method, the method comprising: obtaining a structure to be processed in a target database; serializing the structure to be processed to obtain test data of the structure to be processed after serialization, and storing the test data in the target database.

[0006] In some embodiments of the present disclosure, obtaining the to-be-processed structure in the target database includes: generating the to-be-processed structure using a data generation request and the target database sent by a stress testing tool.

[0007] In some embodiments of the present disclosure, serializing a structure to be processed to obtain test data of the structure to be processed after serialization, and storing the test data in a target database includes: determining whether to call a serialization function based on a breakpoint triggering condition of the structure to be processed; if the serialization function is called, serializing all member variables in the structure to be processed in turn according to the serialization function to obtain test data of all member variables after serialization; and storing the test data in a target data table in the target database.

[0008] In some embodiments of the present disclosure, determining whether to call a serialization function based on the breakpoint triggering situation of the structure to be processed includes: if the structure to be processed triggers the first breakpoint, traversing the member variables of the structure to be processed in the currently executed function to determine the type of the member variables; if the type of the member variables is the same as the type in the preset configuration file, monitoring whether the member variables change; if the member variables change, determining that the structure to be processed triggers the first breakpoint again; and determining that the structure to be processed triggers the first breakpoint again, determining to call the serialization function.

[0009] In some embodiments of the present disclosure, if a serialization function is called, all member variables in the structure to be processed are serialized in turn according to the serialization function, and test data of all member variables after serialization is obtained, including: if the serialization function is called, it is determined whether the first member variable in the structure to be processed is a substructure; if the first member variable is not a substructure, it is determined whether the first member variable is marked, and the marking is used to indicate that the member variable has completed serialization; if the first member variable is not marked, the first member variable is serialized according to the serialization function to obtain test data of the first member variable after serialization, and the first member variable after serialization is marked.

[0010] In some embodiments of the present disclosure, if the structure to be processed triggers the first breakpoint, the member variables of the structure to be processed in the currently executed function are traversed to determine the type of the member variables. The previous method also includes: setting multiple breakpoints for the structure to be processed according to the breakpoint position in the preset configuration file, and the multiple breakpoints include the first breakpoint.

[0011] In some embodiments of the present disclosure, serialization processing is performed on the structure to be processed to obtain test data of the structure to be processed after serialization processing, including: if the number of test data obtained by the structure to be processed triggering the first breakpoint multiple times is equal to a preset value or the algorithm execution time period is equal to the preset time period, then stop generating test data, and the start time of the algorithm execution time period is the time when the structure to be processed is generated.

[0012] A second aspect of the present disclosure provides a test data generating device, the device comprising:

[0013] An acquisition unit, used for acquiring a structure to be processed in a target database;

[0014] The processing unit is used to perform serialization processing on the structure to be processed, obtain test data of the structure to be processed after serialization processing, and store the test data in the target database.

[0015] The third aspect embodiment of the present disclosure proposes an electronic device, comprising: a processor and a memory for storing a computer program that can be run on the processor, wherein the processor, when used to run the computer program, executes the method described in the first aspect embodiment of the present disclosure.

[0016] The fourth aspect embodiment of the present disclosure proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method described in the first aspect embodiment of the present disclosure.

[0017] The fifth aspect embodiment of the present disclosure provides a computer program product, including a computer program, which implements the method described in the first aspect embodiment of the present disclosure when executed by a processor.

[0018] In summary, according to the test data generation method proposed in the present invention, by obtaining the structure to be processed in the target database; serializing the structure to be processed to obtain the test data of the structure to be processed after serialization, and storing the test data in the target database, the test data is automatically generated and stored in the database for use in all subsequent unit tests, thereby reducing the workload of unit testing and improving the efficiency of unit testing.

[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0021] Figure 1 A schematic diagram showing the time consumption comparison of each phase of a software test provided by an embodiment of the present disclosure;

[0022] Figure 2 A flow chart of a test data generating method provided by an embodiment of the present disclosure;

[0023] Figure 3 A schematic diagram of a structure to be processed of a MySQL database provided in an embodiment of the present disclosure;

[0024] Figure 4 A flow chart of a test data generating method provided by an embodiment of the present disclosure;

[0025] Figure 5 A flow chart of a test data generating method provided by an embodiment of the present disclosure;

[0026] Figure 6 A schematic diagram of a specific format in a preset configuration file provided in an embodiment of the present disclosure;

[0027] Figure 7 A flowchart of a specific process of serializing a structure to be processed provided by an embodiment of the present disclosure;

[0028] Figure 8 A schematic diagram of a specific use of test data in a target database provided by an embodiment of the present disclosure;

[0029] Fig. 9 A schematic diagram of a specific test data generation and use provided by an embodiment of the present disclosure;

[0030] Fig.10 A schematic diagram of the structure of a test data generating device provided in an embodiment of the present disclosure;

[0031] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0032] The embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions.

[0033] Software testing is the process of executing a program to find errors, and is a key step in software quality assurance. According to the development stage, software testing can be divided into unit testing, integration testing, system testing, and acceptance testing.

[0034] Unit testing refers to checking and verifying the smallest testable unit in the software. The unit can be a function or a functional module. According to statistics, about 80% of errors are introduced during the software design phase, and the cost of fixing an error will increase as the software life cycle develops. Figure 1 As shown, the present disclosure provides a schematic diagram comparing the time consumed in each stage of software testing, from which it can be seen that if an error is discovered in the unit testing stage, it takes an average of 3.25 hours. If it is omitted in the system testing stage, it will take 11.5 hours. Therefore, it is necessary to discover and solve problems as early as possible.

[0035] At present, in most cases of the related technology, writing unit tests is done manually, that is, the test data in the unit test is written by the developer at will. These test data are relatively simple and it is difficult to find potential problems in the software, and writing test data also consumes a lot of time.

[0036] In actual production, the code of a project can easily reach hundreds of thousands of lines, and as the software is constantly modified and improved, the amount of code will become larger and larger. In these projects, there are some complex classes, structures, etc., and these complex classes and structures are nested in other complex classes and structures. In the process of stable operation of the system, these structures will be initialized and assigned values ​​reasonably, but in unit testing, the values ​​of these structures need to be set manually. If there are only a few simple variables in the structure, there will be no obvious problems in manually setting these variables, but if these variables are very complex, manual setting becomes unreasonable. And it is easy to encounter null pointer errors or assertion errors when the values ​​of variables are randomly written, thereby reducing the efficiency of unit testing.

[0037] The method proposed in the present disclosure can generate test data efficiently and reliably, and can be widely used in scenarios such as software development, database testing, business scenario simulation, scientific research and education, and network security, and is not limited in the embodiments of the present disclosure.

[0038] The test data generating method provided in this application is described in detail below with reference to the accompanying drawings.

[0039] Figure 2 A flow chart of a test data generation method provided by an embodiment of the present disclosure. Figure 2 As shown, the test data generating method includes steps 101-102.

[0040] Step 101, obtaining the structure to be processed in the target database.

[0041] In an embodiment of the present disclosure, the present disclosure can obtain the to-be-processed structure in the database from the target database according to the database query statement of the target database. The target database refers to the database for which test data is currently required to be generated. The target database in the present disclosure takes MySQL database as an example, and may also be other relational databases (such as PostgreSQL, Oracle, SQL Server, etc.)

[0042] The structure to be processed refers to data of a specific structure stored in a table or view in the target database. Figure 3 As shown, the present disclosure provides a schematic diagram of a structure to be processed of a MySQL database. The MySQL database is open source and supports multiple operating systems, but the project code is large and complex. Figure 3In the figure, dict_table_t is the structure to be processed of the database table, which has more than seventy member variables, including some simple member variables such as id, name, etc., as well as some simple sub-structures, such as the structure array dict_col_t describing the columns, and some complex sub-structures, such as the dict_index_t structure storing the index, which also contains dozens of member variables.

[0043] Step 102, serializing the structure to be processed to obtain test data of the structure to be processed after serialization, and storing the test data in a target database.

[0044] In the embodiments of the present disclosure, serialization refers to the process of converting a structure to be processed into a transmittable sequence of bytes. In the present disclosure, it refers to converting a structure to be processed into a string or byte stream (such as JSON, XML, and binary format, etc.) so that it can be transferred between different systems or components. It should be noted that when selecting a serialization method, the present disclosure needs to weigh and select according to the specific application scenario and requirements, which is not limited in the embodiments of the present disclosure.

[0045] The present disclosure converts a to-be-processed structure obtained from a target database into a string in a format suitable for storage or transmission, namely, test data, according to a serialization processing method in a current practical scenario.

[0046] After serializing the structure to be processed, the present disclosure can store the test data obtained after the serialization process in the target database, so that the test data can be used in subsequent unit testing processes.

[0047] In summary, according to the test data generation method proposed in the present invention, by obtaining the structure to be processed in the target database; serializing the structure to be processed to obtain the test data of the structure to be processed after serialization, and storing the test data in the target database, the test data is automatically generated and stored in the target database for use in all subsequent unit tests, thereby reducing the workload of unit testing and improving the efficiency of unit testing.

[0048] As a possible implementation, Figure 4 The flowchart of a test data generation method shown in FIG. 1 is a flowchart of a test data generation method, based on the above embodiment, the specific process of obtaining the structure to be processed in the target database includes the following steps:

[0049] Step 201: Generate a request and a target database using the data sent by the stress testing tool to generate a structure to be processed.

[0050] In the embodiments of the present disclosure, since a system that is running stably cannot be stopped and started at will in actual production, in order to simulate the database load in a real environment without affecting the stability of the production environment, the present disclosure can use the sysbench stress testing tool to simulate the real scene, that is, it can obtain enough structures to be processed, and it will not affect the production environment. Sysbench is a modular, cross-platform, multi-threaded benchmark tool, which is mainly used to evaluate the database load under various system parameters. It can generate a large number of tables and data through a simple one-line command, so as to simulate the real scene and obtain the required data.

[0051] During the simulation process, the present disclosure can generate a large number of tables and data (ie, structures to be processed) by configuring the parameters in the stress testing group to simulate database operations and data generation in real scenarios.

[0052] In summary, the present disclosure can effectively simulate the database load in real scenarios by using the structure to be processed generated by the sysbench stress testing tool, so that the generated structure to be processed is closer to the production environment, which not only ensures the stability of the production environment, but also improves the efficiency and accuracy of testing and analysis.

[0053] As a possible implementation, Figure 5 The flowchart of a test data generation method shown in the figure, based on the above embodiment, serializes the structure to be processed, obtains the test data of the structure to be processed after serialization, and stores the test data in the target database, including the following steps:

[0054] Step 301, determining whether to call a serialization function according to the breakpoint triggering condition of the structure to be processed.

[0055] In an embodiment of the present disclosure, if the structure to be processed triggers the first breakpoint, the member variables of the structure to be processed in the currently executed function are traversed to determine the type of the member variables; if the type of the member variables is the same as the type in the preset configuration file, whether the member variables change is monitored; if the member variables change, it is determined that the structure to be processed triggers the first breakpoint again; after determining that the structure to be processed triggers the first breakpoint again, it is determined to call the serialization function.

[0056] If the structure to be processed triggers the first breakpoint, the member variables of the structure to be processed in the current execution function are traversed to determine the types of the member variables. Previously, the present disclosure also includes: according to the breakpoint positions in the preset configuration file, multiple breakpoints are set for the structure to be processed, and the multiple breakpoints include the first breakpoint.

[0057] In an optional embodiment of the present disclosure, in order to serialize the structure to be processed, the present disclosure needs to consider how to call the serialization function. In the present disclosure, the GDB debugging tool can be used to determine whether to call the serialization function according to the breakpoint triggering situation of the structure to be processed. GDB (GNU Debugger) is a powerful debugging tool under UNIX. The value of the variable can be viewed during debugging, and GDB can use scripts. Users can customize GDB commands in the script to complete some complex tasks.

[0058] Since the present disclosure may generate a large number of structures to be processed, the present disclosure needs to use the GDB debugging tool to set breakpoints wherever these structures to be processed appear. It should be noted that in the present disclosure, not all places where structures to be processed appear can be used, because there may be cases where the structures to be processed are empty or invalid. Therefore, the selection of breakpoint positions in the present disclosure also requires user specification, that is, the user specifies the breakpoint position and fills it in the configuration file in a specific format. There is no need to manually set breakpoints later, and breakpoints can be set directly according to the breakpoint positions in the preset configuration file, thereby realizing the reuse of breakpoints. Figure 6 The figure shows a schematic diagram of a specific format in a preset configuration file provided by the present disclosure. Figure 6 Each data type data_type is a group, which contains multiple breakpoint position setting methods, such as breakpoints based on file names and line numbers, and breakpoints based on function names. Users can freely choose according to actual needs, and there is no restriction in the embodiments of the present disclosure.

[0059] After the GDB debugging tool is started, the disclosed execution script can automatically set breakpoints according to all breakpoint positions recorded in the preset configuration file, and the preset configuration file can also add or delete some breakpoints at any time as needed, so as to make the scalability better. For example, if a new structure to be processed is added to the target database, it is necessary to add breakpoints for it in the preset configuration file to generate test data for it. In addition to the function of automatically setting breakpoints according to the preset configuration file, the script can also traverse the member variables in the currently executed function after triggering the first breakpoint, and judge the type of the member variable in the loop. If it is the same as the type data_type in the preset configuration file, use the monitoring (watch) command to monitor the changes of this member variable. If the member variable is detected to have changed, the first breakpoint is triggered again, the serialization function is called, and the structure data is saved, thereby realizing non-invasive saving of the required data.

[0060] It should be noted that the purpose of triggering breakpoints twice in the present disclosure is to avoid the situation where the structure to be processed is empty after the first breakpoint is triggered for the first time. If the structure to be processed is not empty, the present disclosure can also directly call the serialization function after the first breakpoint is triggered for the first time.

[0061] Step 302: If the serialization function is called, all member variables in the structure to be processed are serialized in turn according to the serialization function to obtain test data of all member variables after serialization.

[0062] In an embodiment of the present disclosure, if a serialization function is called, it is determined whether the first member variable in the structure to be processed is a substructure; if the first member variable is not a substructure, it is determined whether the first member variable is marked, and the marking process is used to indicate that the member variable has completed serialization processing; if the first member variable is not marked, the first member variable is serialized according to the serialization function to obtain test data of the first member variable after serialization processing, and the first member variable after serialization processing is marked.

[0063] In an optional embodiment of the present disclosure, there are many open source methods for serialization processing, which can be selected according to specific scenarios, and are not limited in the embodiments of the present disclosure. When serializing the structure to be processed, the present disclosure needs to consider the mutual reference between structures. For example, for convenience, refer to Figure 2 , the dict_table_t table structure contains the dict_index_t index structure, and the dict_index_t index structure contains the dict_table_t table structure. If nothing is done, it will loop indefinitely. Figure 7 The present disclosure provides a flowchart of a specific process of serializing a structure to be processed. In the process of serializing the structure to be processed, the present disclosure can maintain an object list in which objects that have been serialized are stored. When serializing the first member variable in the structure to be processed, it is determined whether the current object already exists in the object list (or member list). If not, the serialization process continues. If so, the first member variable is marked. According to the recursive processing method, the above judgments are performed on the bytes in the structure to be processed in turn to complete the serialization process.

[0064] Among them, since the process of generating test data in the present disclosure is automated, the present disclosure needs to set a state of judging the end. That is, the structure to be processed is serialized, and the test data of the structure to be processed after serialization includes: if the number of test data obtained by the structure to be processed triggering the first breakpoint multiple times is equal to the preset value or the algorithm execution time period is equal to the preset time period, then stop generating test data, and the start time of the algorithm execution time period is the time of generating the structure to be processed.

[0065] Step 303: Store the test data in a target data table in a target database.

[0066] In the embodiment of the present disclosure, since the serialized test data is in the form of a string, and there are an indefinite number of multiple structures, and each structure will store multiple copies of different data, if it is saved in a text file, additional time is required to parse the file. Therefore, the present disclosure can directly store all the test data in a data table in the database. The field in the data table contains data_type of type varchar and a serialized string of type varchar, and contains an auto-increment id for distinguishing different data of the same type (data_type). When using the test data, the required test data can be obtained according to the type (data_type) by calling the type name query statement, and the deserialization function is called to return the structure with the assignment completed, so as to perform subsequent unit testing.

[0067] Specifically, Figure 8 As shown, the present disclosure provides a specific schematic diagram of using the test data in the target database, using the type name query statement of the target database to obtain the test data stored in the target database, using the deserialization function to deserialize the test data, assigning values ​​to the test data, and obtaining the structure required for the unit test. Deserialization refers to the process of restoring a byte sequence to an object.

[0068] In summary, the test data generation method disclosed in the present invention realizes automatic and non-invasive generation of test data by using GDB scripts and configuration files, which saves a lot of time compared to manual writing, and persists the test data in the target database for repeated use.

[0069] based on Figures 1 to 8 The embodiment shown, as Fig. 9 The present disclosure provides a schematic diagram of specific test data generation and use.

[0070] In the embodiments of the present disclosure, the present disclosure can be divided into two parts, namely, the generation and use of test data required for unit testing. The generation phase is to serialize the structures to be processed used in the test and store them in the target database. The use phase is to deserialize the test data stored in the target database. Fig. 9 , the left side is the flowchart for generating test data, and the right side is the flowchart for using test data.

[0071] In the test data generation stage, the present invention discloses that after the user fills in the configuration file and obtains the preset configuration file, a script can be written to customize the GDB command. At this time, the GDB debugging tool is started to execute the script, and the script automatically breaks the point according to the preset configuration file. When the data generated by the pressure measurement tool (sysbench) and the target database are used to generate the structure to be processed, the structure to be processed triggers a breakpoint (for example, the first breakpoint), then the member variables of the structure to be processed in the current execution function are traversed to determine the type of the member variables; if the type of the member variable is the same as the type in the preset configuration file, the watch command (monitoring command) is used to monitor whether the member variables change; if the member variables change, it is determined that the structure to be processed triggers the first breakpoint again; after determining that the structure to be processed triggers the first breakpoint again, it is determined to call the serialization function. At this time, all member variables in the structure to be processed are serialized in turn according to the serialization function, and the test data after all member variables are serialized is obtained; the test data is stored in the target data table in the target database. If the number of test data obtained by the structure to be processed triggering the first breakpoint multiple times is equal to the preset value or the algorithm execution time period is equal to the preset time period, the stop condition is met, and the generation of test data is stopped at this time. The start time of the algorithm execution time period is the time when the structure to be processed is generated.

[0072] During the data usage stage, the present invention can write the code for the current unit test, call the function according to the type name of the structure in the code, obtain the test data of the type corresponding to the type name from the target database, and call the deserialization function to deserialize the test data, thereby obtaining the final required structure for unit testing.

[0073] Corresponding to the methods provided in the above-mentioned embodiments, the present disclosure also provides a test data generating device. Since the device provided in the embodiments of the present disclosure corresponds to the methods provided in the above-mentioned embodiments, the implementation method of the method is also applicable to the device provided in this embodiment and will not be described in detail in this embodiment.

[0074] Fig.10 FIG. 1 is a schematic diagram of a test data generating device 1000 provided in an embodiment of the present disclosure. Fig.10 As shown, the test data generating device comprises:

[0075] An acquisition unit 1010 is used to acquire a structure to be processed in a target database;

[0076] The processing unit 1020 is used to perform serialization processing on the structure to be processed, obtain test data of the structure to be processed after the serialization processing, and store the test data in the target database.

[0077] In some embodiments of the present disclosure, the acquisition unit 1010 is used to: generate a to-be-processed structure by using the data generation request and the target database sent by the stress testing tool.

[0078] In some embodiments of the present disclosure, the processing unit 1020 is used to: determine whether to call a serialization function based on the breakpoint triggering situation of the structure to be processed; if the serialization function is called, serialize all member variables in the structure to be processed in turn according to the serialization function to obtain test data after all member variables are serialized; and store the test data in a target data table in a target database.

[0079] In some embodiments of the present disclosure, the processing unit 1020 is used to: if the structure to be processed triggers the first breakpoint, traverse the member variables of the structure to be processed in the currently executed function to determine the type of the member variables; if the type of the member variables is the same as the type in the preset configuration file, monitor whether the member variables change; if the member variables change, determine that the structure to be processed triggers the first breakpoint again; after determining that the structure to be processed triggers the first breakpoint again, determine to call the serialization function.

[0080] In some embodiments of the present disclosure, the processing unit 1020 is used to: if a serialization function is called, determine whether the first member variable in the structure to be processed is a substructure; if the first member variable is not a substructure, determine whether the first member variable has been marked, and the marking process is used to indicate that the member variable has completed serialization; if the first member variable has not been marked, serialize the first member variable according to the serialization function to obtain test data of the first member variable after serialization, and mark the first member variable after serialization.

[0081] In some embodiments of the present disclosure, the processing unit 1020 is also used to: if the structure to be processed triggers the first breakpoint, traverse the member variables of the structure to be processed in the currently executed function to determine the type of the member variables. Before that, set multiple breakpoints for the structure to be processed according to the breakpoint positions in the preset configuration file, and the multiple breakpoints include the first breakpoint.

[0082] In some embodiments of the present disclosure, the processing unit 1020 is used to: stop generating test data if the number of test data obtained by the structure to be processed triggering the first breakpoint multiple times is equal to a preset value or the algorithm execution time period is equal to a preset time period, and the start time of the algorithm execution time period is the time when the structure to be processed is generated.

[0083] In summary, through the test data generating device, the structure to be processed in the target database is obtained; the structure to be processed is serialized to obtain the test data of the structure to be processed after serialization, and the test data is stored in the target database, so as to realize automatic generation of test data and store the test data in the database for use in all subsequent unit tests, thereby reducing the workload of unit testing and improving the efficiency of unit testing.

[0084] In the embodiments provided in the present application, the methods and devices provided in the embodiments of the present application are introduced. In order to implement the functions in the methods provided in the embodiments of the present application, the electronic device may include a hardware structure and a software module, and implement the functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. A function of the functions may be executed in the form of a hardware structure, a software module, or a hardware structure plus a software module.

[0085] Fig.11 1 is a block diagram of an electronic device 1100 for implementing the test data generation method according to an exemplary embodiment. For example, the electronic device 1100 may be a mobile phone, a computer, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0086] Reference Fig.11 The electronic device 1100 may include a communication interface 1101, which can interact with other devices; a processor 1102, which is connected to the communication interface 1101 to interact with other devices and is used to execute the method provided by one or more of the above technical solutions when running a computer program; and a memory 1103, on which the computer program is stored. Specifically, the specific processing process of the processor 1102 can refer to the test data generation method described in the above embodiment of the present disclosure.

[0087] Of course, in actual application, the various components in the electronic device 1100 are coupled together through the bus system 1104. It can be understood that the bus system 1104 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 1104 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Fig.11 Various buses are labeled as bus system 1104 .

[0088] The memory 1103 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device 1100. Examples of such data include: any computer program used to operate on the electronic device 1100.

[0089] The method disclosed in the above embodiment of the present application can be applied to the processor 1102, or implemented by the processor 1102. The processor 1102 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 1102. The above processor 1102 may be a general-purpose processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 1102 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present application, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium, which is located in the memory 1103, and the processor 1102 reads the information in the memory 1103, and completes the steps of the above method in combination with its hardware.

[0090] In an exemplary embodiment, the electronic device 1100 can be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.

[0091] The embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the test data generating method described in the above embodiments of the present disclosure.

[0092] The embodiments of the present disclosure further provide a computer program product, including a computer program, which executes the test data generating method described in the above embodiments of the present disclosure when a processor executes the computer program.

[0093] An embodiment of the present disclosure also proposes a chip, which includes one or more interface circuits and one or more processors; the interface circuit is used to receive signals from a memory of an electronic device and send signals to the processor, the signals include computer instructions stored in the memory, and when the processor executes the computer instructions, the electronic device executes the test data generation method described in the above embodiments of the present disclosure.

[0094] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure 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 disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0095] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0096] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.

[0097] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processing module, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (control method), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.

[0098] It should be understood that the various parts of the embodiments of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0099] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0100] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0101] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A test data generation method, characterized in that: The method comprises: Get the structure to be processed in the target database; The structure to be processed is serialized to obtain test data of the structure to be processed after the serialization process, and the test data is stored in the target database.

2. The method according to claim 1, characterized in that The step of obtaining the structure to be processed in the target database includes: Use the data sent by the stress testing tool to generate requests and target databases, and generate structures to be processed.

3. The method according to claim 1, characterized in that: The serializing the structure to be processed, obtaining the test data of the structure to be processed after the serialization, and storing the test data in the target database comprises: Determine whether to call a serialization function according to the breakpoint triggering condition of the structure to be processed; If the serialization function is called, all member variables in the structure to be processed are serialized in turn according to the serialization function to obtain test data of all member variables after serialization; The test data is stored in a target data table in the target database.

4. The method according to claim 3, characterized in that Determining whether to call a serialization function according to the breakpoint triggering condition of the structure to be processed includes: If the structure to be processed triggers the first breakpoint, traverse the member variables of the structure to be processed in the current execution function to determine the types of the member variables; If the type of the member variable is the same as the type in the preset configuration file, monitoring whether the member variable changes; If the member variable changes, determining that the structure to be processed triggers the first breakpoint again; When it is determined that the to-be-processed structure triggers the first breakpoint again, it is determined to call a serialization function.

5. The method according to claim 3, characterized in that: If the serialization function is called, all member variables in the structure to be processed are serialized in sequence according to the serialization function, and the test data of all member variables after serialization is obtained includes: If the serialization function is called, it is determined whether the first member variable in the structure to be processed is a substructure; If the first member variable is not a substructure, determining whether the first member variable is subjected to a marking process, wherein the marking process is used to indicate that the member variable has completed serialization processing; If the first member variable has not been marked, the first member variable is serialized according to the serialization function to obtain test data of the first member variable after serialization, and the serialized first member variable is marked.

6. The method according to claim 4, characterized in that If the structure to be processed triggers the first breakpoint, traversing the member variables of the structure to be processed in the currently executed function to determine the types of the member variables, the method also includes: According to the breakpoint positions in the preset configuration file, a plurality of breakpoints are set for the structure to be processed, wherein the plurality of breakpoints include a first breakpoint.

7. The method according to claim 4, characterized in that The serialization process is performed on the structure to be processed to obtain test data of the structure to be processed after the serialization process, including: If the number of test data obtained by the structure to be processed triggering the first breakpoint multiple times is equal to a preset value or the algorithm execution time period is equal to a preset time period, then stop generating the test data, and the start time of the algorithm execution time period is the time when the structure to be processed is generated.

8. A test data generating device, characterized in that: The device comprises: An acquisition unit, used for acquiring a structure to be processed in a target database; The processing unit is used to perform serialization processing on the structure to be processed, obtain test data of the structure to be processed after the serialization processing, and store the test data in the target database.

9. An electronic device, characterized in that: include: a processor and a memory for storing a computer program capable of being executed on the processor, Wherein, when the processor is used to run the computer program, it executes the method described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 7.