A test data generation method based on database query statements

Through the test data generation method based on database query statements, the problem of complex and incomplete test data construction with complex query statements is solved, the validity and comprehensiveness of the data are achieved, human resources are saved, test efficiency is improved, and the test data in complex statements is ensured. Query operator test coverage.

CN118427110BActive Publication Date: 2024-09-24JIANGSU HUAKU DATA TECH CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410895880.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-05
Publication Date
2024-09-24
Estimated Expiration
2044-07-05

AI Technical Summary

Technical Problem

In database software systems, the test data for complex query statements is complex and incomplete in structure, resulting in problems not being discovered during the testing process, affecting product quality and user experience. The existing methods of manually generating or automatically generating data are time-consuming and wasteful of manpower.

Method used

Provides a test data generation method based on database query statements. It collects test cases, traverses table information to obtain column types, generates data rules and ranges, parses filter condition information, and generates test data that meets or does not meet the filter conditions to ensure the accuracy of the data. Effectiveness and comprehensiveness.

Benefits of technology

It improves the effectiveness and comprehensiveness of test data for complex query statements, saves human resources, and improves test efficiency. By setting the aggregation column repetition rate and data hit rate, it generates test data sets with different characteristics, covering different query operators. Testing requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118427110B
    Figure CN118427110B
Patent Text Reader

Abstract

The present invention provides a method for generating test data based on database query statements, which relates to the field of database testing technology, and specifically includes: collecting test cases; traversing table information according to the test cases to obtain column types; generating data rules and data ranges from the column types; parsing the test cases to obtain filtering condition information; and generating test data within the data range according to the data rules and filtering condition information. The present invention can improve the effectiveness and comprehensiveness of complex query statement test data, and improve test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database testing, and in particular to a method for generating test data based on database query statements. Background Art

[0002] In the field of database software systems, database query operation statements are the most basic and critical functional points of the entire software system. With the advent of the big database era, the huge amount of data and complex relationships have led to the increasingly common application of complex query statements in database software systems. Therefore, the correctness of complex query statements based on the database directly affects the quality of the software system.

[0003] When testing complex query statements, the construction of test data is very complicated, and it is necessary to consider the characteristics of the data according to different query operators. If the test data is not constructed correctly or completely, a large number of problems will not be discovered during the test process, which will have a serious impact on product quality and user experience.

[0004] Currently, testing of complex query statements generally involves manually generating data or automatically generating data based on table creation statements. Both methods require multiple operations and changes to generate valid test data required for complex query statements. The process is complicated and wastes manpower. Summary of the invention

[0005] The present invention aims to solve at least one of the technical problems existing in the related art. To this end, the present invention provides a test data generation method based on a database query statement.

[0006] The present invention provides a method for generating test data based on a database query statement, comprising:

[0007] S1: Collect test cases;

[0008] S2: traverse the table information according to the test case to obtain the column type;

[0009] S3: Generate data rules and data ranges based on the column type;

[0010] S4: parsing the test case to obtain filtering condition information;

[0011] S5: Generate test data within the data range according to the data rule and the filtering condition information.

[0012] According to a test data generation method based on a database query statement provided by the present invention, the test case in step S1 includes:

[0013] The query statement to be tested and the information of the table to be tested involved in the query statement to be tested.

[0014] According to a test data generation method based on a database query statement provided by the present invention, the column type in step S2 includes:

[0015] Numeric type, date type and character type.

[0016] According to a test data generation method based on a database query statement provided by the present invention, step S3 specifically includes:

[0017] When the column type is a numeric type, the data rule is a numeric type data generation rule, and the data range is a type range boundary value of the numeric type;

[0018] When the column type is a date type, the data rule is a date type data generation rule, and the data range is a type range boundary value of the date type;

[0019] When the column type is a character type, the data rule is a character type data generation rule, and the data range is a character type length range generated according to a dictionary file.

[0020] According to a test data generation method based on a database query statement provided by the present invention, in step S3, when the column type has a keyword identifier, the data rule is a custom rule.

[0021] According to a test data generation method based on database query statements provided by the present invention, in step S4, the test case is parsed by retrieving query keywords, and the query keywords include where, group by, and, or, like and in.

[0022] According to a test data generation method based on a database query statement provided by the present invention, step S5 specifically includes:

[0023] S51: Generate test data that meets the data range and the filtering condition information;

[0024] S52: Generate test data that meets the data range and does not meet the filtering condition information.

[0025] According to a test data generation method based on a database query statement provided by the present invention, S51 further includes:

[0026] S511: traverse the column data range of each column in the filtering condition information;

[0027] S512: replacing the data range with the column data range as a narrowed first data range;

[0028] S513: Generate test data that conforms to the data range and the filtering condition information according to the data rule and the first data range.

[0029] According to a test data generation method based on a database query statement provided by the present invention, S52 further includes:

[0030] S521: Subtract the data range from the first data range to obtain a difference data range that has no intersection between the data range and the first data range;

[0031] S522: Replace the data range with the difference data range as a second data range;

[0032] S523: Generate test data that meets the data range and does not meet the filtering condition information according to the data rule and the second data range.

[0033] The present invention provides a test data generation method based on database query statements. By acquiring the column type of the test case and parsing to obtain the data generation rule and filtering condition information, and then generating the test data, the method can ensure the validity and comprehensiveness of the test data of the complex query statement, save human resources and improve the test efficiency, and can generate different test data sets by setting the repetition rate of the aggregated column and the setting of the data hit rate. In addition, the method of determining the data range by querying keywords satisfies the need for test coverage of different query operators used in the statement when testing complex statements, thereby further ensuring the comprehensiveness of the test data.

[0034] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0036] Figure 1 It is a flow chart of a method for generating test data based on database query statements provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical scheme and advantages of the present invention clearer, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. The following embodiments are used to illustrate the present invention, but cannot be used to limit the scope of the present invention.

[0038] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiment of the present invention. In this specification, the schematic representations of the above terms do 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. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0039] In order to better understand the present invention, the terms mentioned in the present invention are explained below.

[0040] Complex query statement: A query statement that uses multiple query operators at the same time and multiple times is called a complex query statement.

[0041] Query keywords: where, group by, and, or, like, in.

[0042] Query operator: corresponds to the query keyword. The comparison between columns in the where condition corresponds to the join operator in the code, the comparison between columns and constants corresponds to the filter operator in the code, and the group by part corresponds to the aggregation operator in the code.

[0043] In a specific embodiment, an example of a query statement is: select t1.a,count(*) cntfrom t1,t2 where t1.a=t2.a and t1.b>10 group by t1.a order by cnt.

[0044] Combine the following Figure 1 Embodiments of the present invention are described.

[0045] like Figure 1 As shown, the present invention provides a test data generation method based on a database query statement, comprising:

[0046] S1: Collect test cases;

[0047] The test case in step S1 includes:

[0048] The query statement to be tested and the information of the table to be tested involved in the query statement to be tested.

[0049] In this phase, you first need to prepare test cases, including complex query statements to be tested and table information involved in the statements. Test cases are a set of conditions or variables that testers use to determine whether the application software or software system works correctly. The method for determining whether a software program or system passes the test is called test criteria.

[0050] S2: traverse the table information according to the test case to obtain the column type;

[0051] The column types in step S2 include:

[0052] Numeric type, date type and character type.

[0053] S3: Generate data rules and data ranges based on the column type;

[0054] Step S3 specifically includes:

[0055] When the column type is a numeric type, the data rule is a numeric type data generation rule, and the data range is a type range boundary value of the numeric type;

[0056] When the column type is a date type, the data rule is a date type data generation rule, and the data range is a type range boundary value of the date type;

[0057] When the column type is a character type, the data rule is a character type data generation rule, and the data range is a character type length range generated according to a dictionary file.

[0058] After step S2, the column type corresponding to each table is obtained by traversing the table information, and then the data generation rule for each column is determined according to the column type in step S3. The numeric type and date type generate legal data within the range according to the type range boundary value, and the character type generates legal data within the character type length range according to the dictionary file.

[0059] In step S3, when the column type has a keyword identifier, the data rule is a custom rule.

[0060] In addition to the data generation rules corresponding to the column types determined above, there is an optional method to generate according to custom rules. This method can be done by adding keywords to the field type to identify it. When the column type is retrieved and the keyword identifier exists, it is generated according to the custom rules.

[0061] In a specific embodiment, such as the id_no bigint column, the data in this column is required to be in the form of an ID number, so the keyword can be defined as id. When the id keyword exists after the column type is retrieved, the data in this column will be generated according to the rules of the ID number.

[0062] S4: parsing the test case to obtain filtering condition information;

[0063] In step S4, the test case is parsed by retrieving query keywords, where the query keywords include where, group by, and, or, like and in.

[0064] In this stage, it is necessary to parse the complex query statement by retrieving query keywords to obtain a set of filtering conditions, where the query keywords include where, group by, and, or, like, and in.

[0065] In a specific embodiment, for example, the statement is:

[0066] select t1.a,count(*) cnt from t1,t2 where t1.a=t2.a and t1.b=t2.b andt1.c like 'abc%'and t1.d<'20230405' group by t1.a order by cnt;

[0067] The filter condition set obtained by parsing the search keywords includes:

[0068] where:

[0069] t1.a=t2.a

[0070] t1.b=t2.b

[0071] t1.c like 'abc%'

[0072] t1.d<'20230405'

[0073] group by:

[0074] t1.a.

[0075] S5: Generate test data within the data range according to the data rule and the filtering condition information.

[0076] Step S5 specifically includes:

[0077] S51: Generate test data that meets the data range and the filtering condition information;

[0078] S51 further includes:

[0079] S511: traverse the column data range of each column in the filtering condition information;

[0080] S512: replacing the data range with the column data range as a narrowed first data range;

[0081] S513: Generate test data that conforms to the data range and the filtering condition information according to the data rule and the first data range.

[0082] When generating legal data that meets the filtering conditions of complex query statements, it is necessary to combine the data generation rules and range of the column, as well as the filtering conditions of the column. First, determine the generation rules and range of legal data, then narrow the data generation range requirements based on the filtering conditions, and finally generate test data based on the data generation rules and the narrowed data generation range requirements.

[0083] The method for narrowing the data generation range requirement according to the filtering conditions is to traverse and parse each filtering condition, and then output the data generation range requirement for each column.

[0084] The following describes the obtained filter condition set based on the specific example in step S4:

[0085] where:

[0086] t1.a=t2.a, which requires that the data range generated by column a of t1 and column a of t2 should be consistent, and the range should be a subset of the data range of column a;

[0087] t1.b=t2.b, which requires that the data range generated by column b of t1 and column b of t2 should be consistent, and the range should be a subset of the data range of column b.

[0088] t1.c like 'abc%', which requires that the first three characters of the t1.c data are abc;

[0089] t1.d<'20230405', requiring the range of t1.d to be date type data less than 20230405;

[0090] group by:

[0091] t1.a, requires to determine the proportion of repeated values ​​in this column. There are two ways to implement this item. One is that the user can set it manually when generating data, and the other is to obtain it randomly, that is, to randomly obtain a value in the range of 1 to 100 each time as the proportion of repeated values.

[0092] S52: Generate test data that meets the data range and does not meet the filtering condition information.

[0093] S52 further comprises:

[0094] S521: Subtract the data range from the first data range to obtain a difference data range that has no intersection between the data range and the first data range;

[0095] S522: Replace the data range with the difference data range as a second data range;

[0096] S523: Generate test data that meets the data range and does not meet the filtering condition information according to the data rule and the second data range.

[0097] When generating legal data that does not meet the requirements of the filtering conditions of a complex query statement, it is necessary to combine the data generation rules and ranges of the columns, as well as the aforementioned data range that meets the filtering conditions. Specifically, first determine the generation rules and ranges of legal data, and then obtain the data range that meets the filtering conditions based on the aforementioned method for generating a narrowed data range. Take two data ranges, namely the first data range and the non-intersecting part of the data range, which are the data generation ranges to be generated that do not meet the filtering conditions. Generate test data based on the data generation rules and the obtained data generation range, that is, the data generation range that does not meet the filtering conditions.

[0098] It should be noted that the proportion of generated data is optional and can be set manually by the user when generating data, or it can be randomly assigned, that is, a value in the range of 1 to 100 is randomly obtained each time as the data hit rate (the amount of matching data divided by the total amount of data).

[0099] It should be noted that a complex query statement can generate multiple data sets with different data characteristics according to this method. For example, the setting of the repetition rate of the aggregate column, different repetition rates will generate data with different characteristics; the setting of the data hit rate, different values ​​will also change the generated test data set; and this method of determining the data range through query keywords meets the need for test coverage of different query operators used in the statement when testing complex statements, thereby effectively ensuring the comprehensiveness of the test data.

[0100] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A test data generation method based on database query statements, characterized in that: include: S1: Collect test cases; S2: traverse the table information according to the test case to obtain the column type; S3: Generate data rules and data ranges based on the column type; S4: parsing the test case to obtain filtering condition information; In step S4, the test case is parsed by searching for query keywords, wherein the query keywords include where, group by, and, or, like, and in; S5: Generate test data within the data range according to the data rule and the filtering condition information; Step S5 specifically includes: S51: Generate test data that meets the data range and the filtering condition information; S52: Generate test data that meets the data range and does not meet the filtering condition information; S51 further includes: S511: traverse the column data range of each column in the filtering condition information; S512: replacing the data range with the column data range as a narrowed first data range; S513: Generate test data that conforms to the data range and the filtering condition information according to the data rule and the first data range; S52 further comprises: S521: Subtract the data range from the first data range to obtain a difference data range that has no intersection between the data range and the first data range; S522: Replace the data range with the difference data range as a second data range; S523: Generate test data that meets the data range and does not meet the filtering condition information according to the data rule and the second data range.

2. A method for generating test data based on database query statements according to claim 1, characterized in that: The test case in step S1 includes: The query statement to be tested and the information of the table to be tested involved in the query statement to be tested.

3. A method for generating test data based on database query statements according to claim 1, characterized in that: The column types in step S2 include: Numeric type, date type and character type.

4. A method for generating test data based on database query statements according to claim 3, characterized in that: Step S3 specifically includes: When the column type is a numeric type, the data rule is a numeric type data generation rule, and the data range is a type range boundary value of the numeric type; When the column type is a date type, the data rule is a date type data generation rule, and the data range is a type range boundary value of the date type; When the column type is a character type, the data rule is a character type data generation rule, and the data range is a character type length range generated according to a dictionary file.

5. A method for generating test data based on database query statements according to claim 4, characterized in that: In step S3, when the column type has a keyword identifier, the data rule is a custom rule.

Citation Information

Patent Citations

  • Method and device for generating test data automatically by utilizing structured query language (SQL) sentences

    CN102043720A

  • Database test data generation method and system thereof

    CN102722537A

  • Software application data generating device and method

    CN104572122A

  • Number generation method, device and equipment of test system and storage medium

    CN112579604A

  • Data generation method and device, electronic equipment and storage medium

    CN115455091A