Method and device for generating relational test data based on formal model
Through the relational test data generation method based on the formal model, the problems of inaccurate test data and low efficiency in the existing technology are solved, efficient and accurate test data generation is achieved, the workload of developers is reduced, and the efficiency of software development is improved. .
Patent Information
- Application Number
- CN202110797161.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-14
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2041-07-14
AI Technical Summary
Existing test data generation technology cannot effectively consider the interrelationship between business scenarios and values, resulting in inaccurate and inefficient generated test data, which increases the workload of developers.
Adopt a relational test data generation method based on formal models, load the target domain data structure through the pre-established domain data structure model library, determine the test domain data items to be generated, and adapt each test domain to be generated according to the data generation strategy Data items to generate relational test data.
It achieves efficient and accurate generation of test data, reduces the cost and workload of test data generation, and improves the efficiency of software development.
Smart Images

Figure CN113448865B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a method and device for generating relational test data based on a formal model. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section.
[0003] Existing test data generation technology can fabricate specific values, but does not consider the business scenarios in which these values are located and the relationship between the values. As a result, in actual testing practice, the test data obtained in this way is actually useless, and this technology is basically ineffective. Developers often still have to write programs to fabricate test data in specific business scenarios. Based on existing technology, the goal of reducing the labor cost required to construct test data cannot be achieved. Therefore, the efficiency and accuracy of existing test data generation solutions are low. Summary of the invention
[0004] An embodiment of the present invention provides a method for generating relational test data based on a formal model, so as to achieve efficient and accurate generation of test data. The method comprises:
[0005] According to the pre-established domain data structure model library, the target domain data structure is loaded to establish the target domain data structure model; the target domain data structure model includes the mutual relationship between domain data items;
[0006] Determine the test domain data items to be generated according to the target domain data structure model; adapt the data generation strategy corresponding to each test domain data item to be generated according to the test domain data items to be generated and the pre-established data generation strategy;
[0007] Relational test data is generated according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model.
[0008] The embodiment of the present invention further provides a relational test data generation device based on a formal model, which is used to efficiently and accurately generate test data. The device includes:
[0009] The formal model modeling component is used to load the target domain data structure according to the pre-established domain data structure model library and establish the target domain data structure model; the target domain data structure model includes the mutual relationship between domain data items;
[0010] The data generation strategy component is used to determine the test domain data items to be generated according to the target domain data structure model; according to the test domain data items to be generated and the pre-established data generation strategy, adapt the data generation strategy corresponding to each test domain data item to be generated;
[0011] The data generation process execution component is used to generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model.
[0012] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned formal model-based relational test data generation method when executing the computer program.
[0013] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above-mentioned formal model-based relational test data generation method.
[0014] In the embodiment of the present invention, the relational test data generation scheme based on the formal model is compared with the technical scheme in the prior art that does not consider the relationship between domain data items, generates inaccurate test data, and has low efficiency. By: loading the target domain data structure according to a pre-established domain data structure model library to establish a target domain data structure model; the target domain data structure model includes the relationship between domain data items; determining the test domain data items to be generated according to the target domain data structure model; adapting the data generation strategy corresponding to each test domain data item to be generated according to the test domain data items to be generated and the pre-established data generation strategy; generating relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model, it is possible to achieve efficient and accurate generation of test data and reduce the cost of generating test data. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0016] Figure 1 Schematic diagram of the process of the method for generating relational test data based on the formal model in an embodiment of the present invention;
[0017] Figure 2It is a flowchart of a method for generating relational test data based on a formal model in another embodiment of the present invention;
[0018] Figure 3 A schematic diagram of a flow chart of an algorithm for iteratively generating test data based on a directed acyclic graph in an embodiment of the present invention;
[0019] Figure 4 It is a structural schematic diagram of a device for generating relational test data based on a formal model in an embodiment of the present invention;
[0020] Figure 5 It is a schematic diagram of the structure of a relational test data generating device based on a formal model in another embodiment of the present invention. DETAILED DESCRIPTION
[0021] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0022] Before introducing the embodiments of the present invention, the terms involved in the implementation of the present invention are first introduced.
[0023] 1. Business domain data structure model: The composition structure of the business data storage model obtained by modeling a specific business domain. In the embodiment of the present invention, it specifically refers to the data logical storage structure under the relational model designed for a specific business domain. The following is a simplified expression, which can be referred to as the domain data structure.
[0024] 2. Business domain data item: In the domain data structure model, a data attribute item in a certain relationship. The following is a simplified expression, which can be referred to as domain data item.
[0025] The following is a detailed introduction to the technical problems found by the inventors in the existing test data generation, and the ideas of the embodiments of the present invention based on the technical problems.
[0026] During software system development, a large number of scenarios require fabricated test data, as shown below:
[0027] 1. Tests at various stages, such as unit testing, integration testing, and user acceptance testing, all require the use of test data to verify the correctness of system functions, and test data often has certain quantity requirements. Especially in the performance testing stage, a large amount of specific test data that meets business specifications must be fabricated, and performance test data often has to meet certain distribution requirements (for example, the proportion of data for certain attributes is large, and the proportion of data for others is relatively small).
[0028] 2. Software systems often need to be migrated to a new environment for testing and verification, and system migration also requires a complete set of test data for the domain business. However, due to environmental factors and various reasons such as security regulations not allowing it, developers can only lay the foundation for the minimum parameter set required for system startup through program scripts during system migration, and cannot directly build a complete business data set through library table backup migration.
[0029] 3. A large number of software projects require the separation of test libraries and production libraries. When testing and verifying the target software system, only fabricated false data can be used for sensitive business.
[0030] Therefore, there is a need to fabricate test data in many scenarios in actual software projects. However, existing test data generation technologies, such as jmockdata, JavaFaker, etc., can randomly generate basic data types, such as strings, numeric types, and dates and times. At the same time, they can also go a step further and fabricate common concepts in a formatted manner, such as generating formatted names, place names, company names, blood types, etc. However, these existing test data generation technologies have the following shortcomings, which prevent the in-depth use of these technologies:
[0031] 1. In the actual software project practice, the test data that needs to be fabricated are all related, and the relationship between business data is often a mixture of hierarchical relationships and network relationships. Although the existing test data generation technology on the market is good at fabricating values out of thin air, it does not care about the position of these values in the actual business scenario, nor the relationship between values. The relationship between values is the key to determining the business significance of values.
[0032] 2. Test data needs to be generated based on existing parameter data, that is, using existing business parameter data to fabricate another type of domain business entity that is related to it (for example, a common scenario is to fabricate a large amount of employee data based on the organizational structure).
[0033] 3. These test data generation techniques often cannot fabricate data in the specific format of certain attribute data of actual business entities.
[0034] Therefore, the task of actually fabricating test data falls on the corresponding developers. This work itself is time-consuming and laborious. A business data table often has dozens of attributes, and there are often hundreds of relationship tables in a system. The process of developing the corresponding test data generation program is both cumbersome and requires carefulness. The relationship between different business data tables must also be considered, and the test data generation program itself needs to be tested. This directly increases the workload for developers, delaying both development and testing. If a test data generation method can be proposed to change the current inefficient mode of constructing test data, the time saved is to tap into the productivity of software development.
[0035] During the development process, the most difficult thing is how to create test data that meets the business scenarios out of thin air. More specifically, how to fabricate test data according to the domain data structure, business constraints of data items, and various non-functional requirements.
[0036] In view of the above technical problems, in order to achieve the above objectives, the embodiment of the present invention proposes a relational test data generation scheme based on a formal model. The most important work implemented in the scheme, that is, the most important technical points are:
[0037] 1. Proposed and implemented a set of methods for formal modeling of business domain data structures based on relational models.
[0038] 2. A method for adapting the constraints of the actual system operating environment and the requirements of target users for domain data items to the domain data model is proposed and implemented. That is, an adaptation mechanism for the test data construction method of domain data items is proposed. An algorithm for iterative generation of test data based on directed acyclic graphs is proposed.
[0039] 3. Based on the formal model obtained in point 1 and the formal model adaptation solution obtained in point 2, a customized test data generation process is executed to directly generate test data with complete association relationships and correct data item formats.
[0040] 4. A component architecture for test data generation is proposed and implemented. Under this architecture, each component works together to achieve the goal of test data generation.
[0041] In summary, the embodiments of the present invention are dedicated to improving the test data generation model, by modeling business domain objects and adapting data generation strategies, so as to achieve the purpose of efficiently and correctly generating test data according to business domain models, thereby reducing or even eliminating the workload required by developers to create test data, reducing the waiting time of testers, and ultimately improving the efficiency of system development. The following is a detailed introduction to the relational test data generation solution based on the formal model.
[0042] Figure 1FIG. 1 is a flow chart of a method for generating relational test data based on a formal model in an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0043] Step 101: According to a pre-established domain data structure model library, a target domain data structure is loaded to establish a target domain data structure model; the target domain data structure model includes the mutual relationship between domain data items;
[0044] Step 102: determining the test domain data items to be generated according to the target domain data structure model; adapting the data generation strategy corresponding to each test domain data item to be generated according to the test domain data items to be generated and the pre-established data generation strategy;
[0045] Step 103: Generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model.
[0046] The formal model-based relational test data generation solution provided by the embodiment of the present invention can achieve efficient and accurate generation of test data, thereby reducing the generation cost of test data.
[0047] The ideas in the embodiment of the present invention are as follows: (1) Describe the relationship between the various data items in the domain data structure through a well-defined formal model, that is, the above step 101. (2) Through the data generation strategy component, the test data generation strategy related to the target environment is reversely adapted to the domain data items through dependency injection, that is, the above step 102. (3) With the domain data structure and the domain data item generation strategy, in the embodiment of the present invention, the conditions for generating test data are met, that is, the above step 103.
[0048] Therefore, the components in the test data generation device can be defined as the following three items: 1. Formal model building component. 2. Data generation strategy component. 3. Data generation process execution component. The definition and association structure of these three modules (components) are as follows: Figure 5 shown.
[0049] 1. First, the above step 101 is introduced. The step 101 can be implemented by a formal model modeling component.
[0050] When implementing it, Figure 2As shown, step 101 is a step for loading and parsing the domain data structure. In this step, the formal model modeling component reads the domain data structure model library and loads the target domain data structure to establish the target domain data structure. At the same time, the modeling component also verifies the correctness of the model and verifies the domain data structure according to the preset rules (strategies), as described in the following embodiments. If the domain data structure is correct and passes the verification, the formal model modeling component presents the data structure to the data generation strategy component. If an exception occurs during the modeling process, an error message is reported and the system exits.
[0051] The responsibilities of the formal model modeling component are as follows: (1) Responsible for defining the domain data structure. (2) Responsible for compiling and parsing the domain data structure description language. (3) Checking the validity of the domain data structure. (4) Presenting a valid domain data structure to the lower-level components that rely on the domain structure model.
[0052] In specific implementation, the core theoretical basis of the formal model modeling component is a formal language that describes relational data structures and associations. The language is defined as follows:
[0053] The domain data structure is defined as Domain(RELS,DF), where:
[0054] Domain represents domain data structures, including RELS and DF.
[0055] RELS, which stands for Relations, represents a collection of relational tables in a domain data structure.
[0056] DF means "determining function set", which means which domain item sets can determine other domain item sets in a relational model. DF can be formally defined as an ordered pair, specifically<P1,P2> In this ordered pair, p1 determines p2. Among them, p1 and p2 are both non-empty subsets of the power set of the attributes of a relational table. If the power set operation is set to pow, since for any R∈RELS, R itself is also a set, the formal definition of DF is as follows:
[0057]
[0058] R1∈RELS;
[0059] R2∈RELS.
[0060] It can be seen that DF constitutes a graph that describes the decision relationship between domain data items. Since the three association structures of autocorrelation, hierarchical structure, and network association structure are sufficiently expressive for real relational models, several constraints can be added to DF, as follows:
[0061] 1. Remove the cyclic structure in the DF graph, so that DF forms a directed acyclic graph.
[0062] 2. If the ordered pairs in DF<P1,P2> , where P1∈pow(R),P2∈pow(R),R∈RELS,
[0063] During specific implementation, the formal model mentioned in the embodiment of the present invention is the target domain data structure model.
[0064] From the above, it can be seen that in one embodiment, if Figure 2 As shown, the above-mentioned formal model-based relational test data generation method may further include: verifying the validity of the target domain data structure model.
[0065] Determining the test domain data items to be generated according to the target domain data structure model; adapting the data generation strategy corresponding to each test domain data item to be generated according to the test domain data items to be generated and the pre-established data generation strategy, may include:
[0066] When it is determined that the target domain data structure model is valid, the test domain data items to be generated are determined according to the valid target domain data structure model; according to the test domain data items to be generated and the pre-established data generation strategy, the data generation strategy corresponding to each test domain data item to be generated is adapted.
[0067] 2. Next, the above step 102 is introduced. The step 101 can be implemented by a data generation strategy component.
[0068] Data generation strategy adaptation step. In this step, the data generation strategy component checks the validity of the strategy, specifically: (1) Determine the target relational table to be generated (the relational table corresponding to the test domain data item to be generated). (2) According to the domain data model, check and confirm that the own attributes of the target relational table have the value generation strategy. (3) According to the domain data model, iteratively check that the determined attribute data items of this table can be recorded in the upstream relational table level by level.
[0069] In specific implementation, the strategies in the data generation strategy library are to pre-write the test data generation program for the target domain data items. This step identifies the target domain data model and the test data to be generated (test data to be generated).
[0070] The responsibilities of the data generation strategy component are: (1) Determine the data generation target, specifically, specify the relational data table in the domain data structure that needs to generate data. (2) Adapt the data generation strategy for each domain data item in the specified relational table. (3) Check whether the data generation strategy completely covers each data item in the target relational table. For specific detection methods, strategies or rules, please refer to the description of the following embodiments. (4) Present the effective data generation strategy to the lower-level modules (components).
[0071] In the specific implementation, in the relational data model (domain data structure model), the relational table includes both its own attributes and the attributes associated with other relational tables (i.e., foreign keys). These associated attribute data items are determined by other relational tables. Therefore, the data generation strategy component needs to check whether both the own attributes and the determined attributes of the target relational table can generate values. The specific strategy is as follows:
[0072] 1. For the relational table that needs to be numerically generated, check whether all its data items are adapted to the value generator.
[0073] 2. Check the determined attribute data item of the relationship table to see whether a record can be selected in the dependent relationship table as the value source of the determined attribute data item.
[0074] 3. The process of checking the determined attribute data items is iterative. That is, for a target relational table that needs to generate test data, the upstream relational table it depends on also needs to be generated. At this time, the domain data structure comes into play. The data generation strategy component can trace the source layer by layer according to the itemized acyclic graph described by the determination function set DF of the domain data structure. An obvious fact is that if the domain data structure is verified to be valid, the method can eventually trace back to the root relational table, so that the target relational tables related before and after can be generated with test data. When each target domain data item can be generated, or generated by tracing back to the source, it can be said that the data generation strategy is complete, otherwise, it is incomplete. The complete data generation strategy will be further presented to the data generation process execution component to complete the final test data generation task.
[0075] From the above, it can be seen that in one embodiment, Figure 2 As shown, the above-mentioned formal model-based relational test data generation method may further include: checking the validity of the data generation strategy corresponding to each test domain data item to be generated.
[0076] Generating relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model may include:
[0077] When the data generation strategy corresponding to each test domain data item to be generated is effective, relational test data is generated according to the effective data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model.
[0078] As can be seen from the above, in one embodiment, checking the validity of the data generation strategy corresponding to each test domain data item to be generated may include:
[0079] Check whether the domain data items of the relational table corresponding to each test domain data item to be generated are adapted to the data generation strategy;
[0080] Checking the determined attribute data item of the relationship table corresponding to each test domain data item to be generated, whether a record can be selected in the dependent relationship table as the value source of the determined attribute data item;
[0081] Checks whether the process of determining the attribute data item is iterative.
[0082] 3. Next, the above step 103 is introduced. The step 101 can be implemented by a data generation process execution component.
[0083] In specific implementation, step 103 is a data generation step. In this step, the data generation process execution component relies on the domain data structure and data generation strategy to iteratively generate test data, and the overall flow chart of the embodiment of the present invention is obtained as follows: Figure 2 This step executes the test data generation program (strategy) to generate target test data.
[0084] The responsibilities of the data generation process execution component are: (1) receiving valid domain data structures and supporting data generation strategies. (2) based on the basis obtained in responsibility (1), driving the data generation process execution until the data generation task is completed, that is, generating test data.
[0085] In this overall step, the data generation step needs to be emphasized. Because the target relationship table also has upstream and downstream associations in the entire domain data model, that is, there are mutual relationships. Therefore, the key point of the data generation process is how to determine the order of generating test data for the target relationship table, that is, to determine which relationship tables are generated first and which relationship tables are generated later. It can be seen from the introduction of the above embodiments that since the domain data structure in the present invention has a directed acyclic characteristic, the problem of determining the order can be done by a directed acyclic graph search algorithm. An embodiment of the present invention provides an algorithm for iteratively generating test data based on a directed acyclic graph as follows:
[0086] 1. Determine the set of relation tables to be created. Let this set be the Target Relation Set, denoted as TRS. This set should not be an empty set.
[0087] 2. Set the root relation set, denoted as RRS, and initialize it to an empty set.
[0088] 3. Select a relation table R in TRS, and check whether the relation table has an upstream relation table UR to determine the attributes of table R according to the domain data structure. If UR does not exist, add relation table R to set RRS and remove relation R from set TRS. If UR exists, remove relation R from set TRS and set R to UR.
[0089] 4. Iterate step 3 until TRS is empty.
[0090] 5. The data generation process execution component iterates the elements of the RRS and generates test data for each root node relationship table according to the established strategy.
[0091] 6. After the data generation process execution component completes the iteration of the elements of RRS, the data generation process execution component iterates the secondary elements of the elements of RRS according to the domain data model to generate test data for the secondary relationship table.
[0092] 7. Iterate step 6 until all levels of target relational tables are populated with test data.
[0093] In specific implementation, the above algorithm for iteratively generating test data based on test data of a directed acyclic graph further improves the quality of test data, that is, further improves the accuracy of test data generation.
[0094] From the above, it can be seen that in one embodiment, if Figure 3 As shown, generating relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model may include:
[0095] Step 201: Determine a set of relational tables corresponding to the test data to be generated; the set of relational tables is a non-empty set;
[0096] Step 202: setting a root node set corresponding to the test data to be generated; the root node set is initialized to an empty set;
[0097] Step 203: iteratively execute the following set processing steps until the relationship table set is an empty set, and find each level of relationship table corresponding to the elements in the root node set:
[0098] Step 2031: Select a relation table from the relation table set, and check whether the selected relation table has an upstream relation table to determine the properties of the selected relation table according to the target domain data structure model;
[0099] Step 2032: if there is no upstream relationship table that determines the properties of the selected relationship table, add the selected relationship table to the root node set, and remove the selected relationship table from the relationship table set; if there is an upstream relationship table that determines the properties of the selected relationship table, remove the selected relationship table from the relationship table set, and set the selected relationship table as the upstream relationship table, until the relationship table set is an empty set, and find each level of relationship table corresponding to the root node relationship table in the root node set;
[0100] Step 204: when the relationship table set is an empty set and each level of relationship table corresponding to the root node relationship table in the root node set is found, iterate the root node relationship tables in the root node set, and generate test data for each root node relationship table in the root node set according to the data generation strategy corresponding to each test domain data item to be generated;
[0101] Step 205: After the iteration of the root node relationship table in the root node set is completed, each level of relationship table corresponding to the root node relationship table in the root node set is iterated in sequence by level until test data is generated for each level of relationship table.
[0102] In order to facilitate understanding of how to implement the present invention, the overall process consisting of the following technical points is emphasized:
[0103] 1. A formal model description method proposed to express relational domain data structure models, and a corresponding domain data structure model checking method.
[0104] 2. Data generation strategy adaptation mechanism and data generation strategy completeness check method.
[0105] 3. An iterative test data construction process from root to branch based on directed acyclic graph search method.
[0106] The most obvious improvement is that, before the present invention, the development and testing of the test data generation program that had to be carried out to fabricate test data has been greatly simplified, or even directly omitted. Moreover, the test data generation mechanism can be customized and migrated. These greatly save the man-hours required for fabricating data in the test phase and improve the efficiency of software development.
[0107] In summary, the method for generating relational test data based on a formal model provided by the embodiment of the present invention realizes:
[0108] 1. Use formal models to model the target business domain data structure, parse the formal model description language, and check the correctness of the formal model. These steps involve the formal model modeling module. This step brings direct benefits. The formal model is not constrained by a specific test environment. As long as the domain data structure is determined, the formal model can be copied and reused in various scenarios and environments, directly eliminating the workload of establishing relationships between tables through mechanical coding in the code.
[0109] 2. Added data generation strategy adaptation mechanism and data generation strategy checking mechanism. There are two advantages: (1) By reversely injecting the data adaptation mechanism, the present invention can dynamically adapt to various test environments and realize code reuse. (2) Through the data generation strategy checking mechanism, before generating numbers, it can be found whether the configuration of the data adaptation strategy is complete. Compared with the traditional coding number generation method, it can more quickly find possible problems in the number generation process.
[0110] 3. A test data generation step based on a directed acyclic graph search algorithm is added. The advantage is that, through graph search, the present invention can directly determine which target tables need to generate test data. In this way, the development work of writing a number-generating program specifically for the target table, which was previously required, can be simplified in the present invention to be achieved simply by configuring the target table.
[0111] The embodiment of the present invention also provides a relational test data generation device based on a formal model, as described in the following embodiment. Since the principle of solving the problem by the device is similar to that of the relational test data generation method based on a formal model, the implementation of the device can refer to the implementation of the relational test data generation method based on a formal model, and the repeated parts will not be repeated.
[0112] Figure 4 FIG. 1 is a schematic diagram of a structure of a relational test data generating device based on a formal model in an embodiment of the present invention. Figure 4 As shown, the device comprises:
[0113] The formal modeling component 01 is used to load the target domain data structure according to the pre-established domain data structure model library and establish the target domain data structure model; the target domain data structure model includes the mutual relationship between domain data items;
[0114] The data generation strategy component 02 is used to determine the test domain data items to be generated according to the target domain data structure model; according to the test domain data items to be generated and the pre-established data generation strategy, adapt the data generation strategy corresponding to each test domain data item to be generated;
[0115] The data generation process execution component 03 is used to generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model.
[0116] In one embodiment, the data generation process execution component can be specifically used to:
[0117] Determine a set of relational tables corresponding to the test data to be generated; the set of relational tables is a non-empty set;
[0118] Set a root node set corresponding to the test data to be generated; the root node set is initialized to an empty set;
[0119] Iterate and execute the following set processing steps until the relationship table set is an empty set, and find each level of relationship table corresponding to the elements in the root node set:
[0120] Select a relational table from the relational table set, and check whether the selected relational table has an upstream relational table to determine the properties of the selected relational table according to the target domain data structure model;
[0121] If there is no upstream relationship table that determines the properties of the selected relationship table, add the selected relationship table to the root node set and remove the selected relationship table from the relationship table set; if there is an upstream relationship table that determines the properties of the selected relationship table, remove the selected relationship table from the relationship table set and set the selected relationship table as the upstream relationship table until the relationship table set is an empty set, and find each level of relationship table corresponding to the root node relationship table in the root node set;
[0122] When the relationship table set is an empty set, when each level of relationship table corresponding to the root node relationship table in the root node set is found, iterate the root node relationship tables in the root node set, and generate test data for each root node relationship table in the root node set according to the data generation strategy corresponding to each test domain data item to be generated;
[0123] After the iteration of the root node relationship table in the root node set is completed, each level of relationship table corresponding to the root node relationship table in the root node set is iterated in sequence by level until test data is generated for each level of relationship table.
[0124] In one embodiment, the formal model building component may also be used to verify the validity of the target domain data structure model.
[0125] In one embodiment, the data generation strategy component may also be used to check the validity of the data generation strategy corresponding to each test domain data item to be generated.
[0126] In one embodiment, the data generation strategy component may be specifically used to:
[0127] Check whether the domain data items of the relational table corresponding to each test domain data item to be generated are adapted to the data generation strategy;
[0128] Checking the determined attribute data item of the relationship table corresponding to each test domain data item to be generated, whether a record can be selected in the dependent relationship table as the value source of the determined attribute data item;
[0129] Checks whether the process of determining the attribute data item is iterative.
[0130] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned formal model-based relational test data generation method when executing the computer program.
[0131] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above-mentioned formal model-based relational test data generation method.
[0132] In the embodiment of the present invention, the relational test data generation scheme based on the formal model is compared with the technical scheme in the prior art that does not consider the relationship between domain data items, generates inaccurate test data, and has low efficiency. By: loading the target domain data structure according to a pre-established domain data structure model library to establish a target domain data structure model; the target domain data structure model includes the relationship between domain data items; determining the test domain data items to be generated according to the target domain data structure model; adapting the data generation strategy corresponding to each test domain data item to be generated according to the test domain data items to be generated and the pre-established data generation strategy; generating relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model, it is possible to achieve efficient and accurate generation of test data and reduce the cost of generating test data.
[0133] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0134] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0135] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0137] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for generating relational test data based on a formal model, characterized in that: include: According to the pre-established domain data structure model library, the target domain data structure is loaded to establish the target domain data structure model; The target domain data structure model includes the relationships between domain data items; Determine the test domain data items to be generated according to the target domain data structure model; According to the test domain data items to be generated and the pre-established data generation strategy, adapt the data generation strategy corresponding to each test domain data item to be generated; Generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model; Generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model, including: Determine a set of relational tables corresponding to the test data to be generated; the set of relational tables is a non-empty set; Set a root node set corresponding to the test data to be generated; the root node set is initialized to an empty set; Iterate and execute the following set processing steps until the relationship table set is an empty set, and find each level of relationship table corresponding to the elements in the root node set: Select a relational table from the relational table set, and check whether the selected relational table has an upstream relational table to determine the properties of the selected relational table according to the target domain data structure model; If there is no upstream relationship table that determines the properties of the selected relationship table, add the selected relationship table to the root node set and remove the selected relationship table from the relationship table set; if there is an upstream relationship table that determines the properties of the selected relationship table, remove the selected relationship table from the relationship table set and set the selected relationship table as the upstream relationship table until the relationship table set is an empty set, and find each level of relationship table corresponding to the root node relationship table in the root node set; When the relationship table set is an empty set, when each level of relationship table corresponding to the root node relationship table in the root node set is found, iterate the root node relationship tables in the root node set, and generate test data for each root node relationship table in the root node set according to the data generation strategy corresponding to each test domain data item to be generated; After the iteration of the root node relationship table in the root node set is completed, each level of relationship table corresponding to the root node relationship table in the root node set is iterated in sequence by level until test data is generated for each level of relationship table.
2. The method for generating relational test data based on a formal model according to claim 1, characterized in that: Also includes: Verify the validity of the target domain data structure model.
3. The method for generating relational test data based on a formal model according to claim 1, characterized in that: Also includes: Check the validity of the data generation strategy corresponding to each test domain data item to be generated.
4. The method for generating relational test data based on a formal model according to claim 3, characterized in that: Check the validity of the data generation strategy corresponding to each test domain data item to be generated, including: Check whether the domain data items of the relational table corresponding to each test domain data item to be generated are adapted to the data generation strategy; Checking the determined attribute data item of the relationship table corresponding to each test domain data item to be generated, whether a record can be selected in the dependent relationship table as the value source of the determined attribute data item; Checks whether the process of determining the attribute data item is iterative.
5. A relational test data generation device based on a formal model, characterized in that: include: The formal model modeling component is used to load the target domain data structure according to the pre-established domain data structure model library and establish the target domain data structure model; The target domain data structure model includes the relationships between domain data items; A data generation strategy component is used to determine the test domain data items to be generated according to the target domain data structure model; According to the test domain data items to be generated and the pre-established data generation strategy, adapt the data generation strategy corresponding to each test domain data item to be generated; A data generation process execution component is used to generate relational test data according to the data generation strategy corresponding to each test domain data item to be generated and the target domain data structure model; The data generation process execution component is specifically used for: Determine a set of relational tables corresponding to the test data to be generated; the set of relational tables is a non-empty set; Set a root node set corresponding to the test data to be generated; the root node set is initialized to an empty set; Iterate and execute the following set processing steps until the relationship table set is an empty set, and find each level of relationship table corresponding to the elements in the root node set: Select a relational table from the relational table set, and check whether the selected relational table has an upstream relational table to determine the properties of the selected relational table according to the target domain data structure model; If there is no upstream relationship table that determines the properties of the selected relationship table, add the selected relationship table to the root node set and remove the selected relationship table from the relationship table set; if there is an upstream relationship table that determines the properties of the selected relationship table, remove the selected relationship table from the relationship table set and set the selected relationship table as the upstream relationship table until the relationship table set is an empty set, and find each level of relationship table corresponding to the root node relationship table in the root node set; When the relationship table set is an empty set, when each level of relationship table corresponding to the root node relationship table in the root node set is found, iterate the root node relationship tables in the root node set, and generate test data for each root node relationship table in the root node set according to the data generation strategy corresponding to each test domain data item to be generated; After the iteration of the root node relationship table in the root node set is completed, each level of relationship table corresponding to the root node relationship table in the root node set is iterated in sequence by level until test data is generated for each level of relationship table.
6. The apparatus for generating relational test data based on a formal model according to claim 5, characterized in that: The formal model building component is also used to verify the validity of the target domain data structure model.
7. The apparatus for generating relational test data based on a formal model according to claim 5, characterized in that: The data generation strategy component is also used to check the validity of the data generation strategy corresponding to each test domain data item to be generated.
8. The apparatus for generating relational test data based on a formal model according to claim 7, characterized in that: The data generation strategy component is specifically used for: Check whether the domain data items of the relational table corresponding to each test domain data item to be generated are adapted to the data generation strategy; Checking the determined attribute data item of the relationship table corresponding to each test domain data item to be generated, whether a record can be selected in the dependent relationship table as the value source of the determined attribute data item; Checks whether the process of determining the attribute data item is iterative.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 4.
