A method for quickly generating DBFIT use cases

By reading and processing SQL text files, combined with database connections and multiple determination mechanisms, it is automatically converted into use cases in DBFIT format, which solves the time-consuming and complex problems of manually writing DBFIT use cases and achieves efficient and accurate use case generation, which is suitable for Multiple database types.

CN118295931BActive Publication Date: 2024-09-24成都虚谷伟业科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In database testing, manually writing DBFIT use cases is time-consuming, labor-intensive, and error-prone. Moreover, the test steps for switching nodes in a distributed database are cumbersome, which increases technical requirements and learning costs. There is an urgent need for a method to quickly generate DBFIT use cases.

Method used

By reading SQL text files, performing data preprocessing, establishing database connections, and using multiple determination mechanisms for statement processing, the SQL statements are finally converted into use cases in DBFIT format, including node switching determination, query statement determination, and annotation information determination, automatically Add use case number and format.

Benefits of technology

It realizes automatic identification and segmentation of SQL statements, generates standardized DBFIT format use cases, reduces tester workload, improves efficiency, lowers technical thresholds, eliminates the need to learn DBFIT fixed syntax, and adapts to multiple database types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118295931B
    Figure CN118295931B
Patent Text Reader

Abstract

The present invention discloses a method for quickly generating DBFIT use cases, which includes the following steps: S1: reading SQL text files; S2: data preprocessing, including segmenting SQL character strings, block statement processing and process function processing; S3: establishing a database; S4: using a multiple determination mechanism to perform determination, so as to achieve the purpose of adding use case numbers, the multiple determination mechanism includes node switching determination, query statement determination and comment information determination; S5: according to the determination result of step S4, selecting different statement processing methods to perform statement processing, and finally obtaining a use case result in DBFIT format. The present invention can automatically identify and segment SQL and generate DBFIT format use cases, which greatly reduces the workload of testers, improves work efficiency, and is not prone to errors.
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 quickly generating a DBFIT test case. Background Art

[0002] DBFIT is an open source framework for database testing, which provides testers with a simple and effective automated testing solution. DBFIT is based on the Java language and uses the FitNesse test framework as its basic component. It supports a variety of database systems (such as MySQL, Oracle, SQL Server, etc.), which is convenient for testing in different database environments. Basic SQL cannot be executed directly in DBFIT. You must first add a fixed format to the SQL use case to be executed, and set the expected output column name and result set; if you write a DBFIT use case manually, you must first execute the SQL statement in the database console to obtain the result column name and result set, and then edit and add the format specified by DBFIT.

[0003] Currently, the number of use cases involved in database testing is very large. Manually writing DBFIT use cases is not only time-consuming and labor-intensive, but also prone to errors, low efficiency and poor quality. In addition, for some scenarios such as distributed database switching node testing, manual execution is also very cumbersome. Use case writers also need to spend time learning the DBFIT format syntax before they can write DBFIT use cases, which increases technical requirements and learning costs. Therefore, a method that can quickly generate DBFIT use cases is urgently needed to solve the above problems. Summary of the invention

[0004] The purpose of the present invention is to provide a method for quickly generating a DBFIT use case, aiming to solve the technical problem of how to quickly generate a DBFIT use case.

[0005] The object of the present invention is to adopt the following technical solution to achieve: a method for quickly generating a DBFIT use case, comprising the following steps:

[0006] S1: read SQL text file;

[0007] S2: data preprocessing, including SQL string segmentation, block statement processing, and procedure function processing;

[0008] S3: Establish database;

[0009] S4: using a multiple determination mechanism to perform determination, so as to achieve the purpose of adding a use case number, wherein the multiple determination mechanism includes node switching determination, query statement determination, and comment information determination;

[0010] S5: According to the determination result of step S4, different statement processing methods are selected to process the statements, and finally a use case result in DBFIT format is obtained.

[0011] Furthermore, step S1 is specifically as follows: using Java's file byte input stream and buffered byte input stream to read the SQL text file content, and appending each line to a variable string Str1.

[0012] Furthermore, step S2 includes the following sub-steps:

[0013] S21: Split the SQL string. Use split and regular expressions to split the SQL text file content stored in the variable string Str1 obtained in step S1 using semicolons plus spaces or tabs as delimiters, and put the split results into the string array Arr1.

[0014] Furthermore, step S2 also includes the following sub-steps:

[0015] S22: Loop through the string array Arr1 obtained in step S21, remove the leading and trailing spaces, and then perform sentence start judgment. If it starts with declare or begin, as well as create procedure or create function, it is judged to be a PL / SQL statement block and is stored in a separate variable string Str2 until a line ending with end is matched. The PL / SQL statement block is judged to be over, and the variable string Str2 is appended as a whole to the string list List1. If it is judged not to be a PL / SQL statement block, it is directly appended to the string list List1 until all contents in the string array Arr1 are processed.

[0016] Furthermore, step S3 specifically includes: establishing connections to each database and each node according to the configured database connection string information, and distinguishing and naming them for use when switching database connections.

[0017] Furthermore, step S4 includes the following sub-steps:

[0018] S41: Node switching judgment, loop processing the string list List1 obtained in step S22, and perform sentence beginning judgment. If it starts with the switch keyword, it is considered to be a node switching statement. According to the number of nodes following it, the value of the Statement object is set to the Statement object created by the corresponding node connection information to achieve the purpose of switching the node, otherwise it is the default node connection; then the current line of the string list List1 to be processed is appended to the final result variable string Str3.

[0019] Furthermore, step S4 also includes the following sub-steps:

[0020] S42: Query statement determination. If the switch node statement is not met after the determination in step S41, the query statement determination is performed. If the SQL obtained in the string list List1 starts with a query keyword, it is identified as a query statement. The query SQL is executed using the Statement object. The returned result is stored in a database result set ResultSet. The current query statement is added with a corresponding format, and appended to the variable string Str3 and wrapped. Then, the column names are obtained from the database result set ResultSet. All column names are formatted and appended to the variable string Str3 and wrapped. Finally, the query results are retrieved from the database result set ResultSet, and the fixed format is added and appended to the variable string Str3 and wrapped.

[0021] Furthermore, step S4 also includes the following sub-steps:

[0022] S43: Determine the comment information. If the SQL obtained from the string list List1 starts with a comment symbol, it is considered as comment information. The comment information is appended to the variable string Str3 and the line is wrapped. Then an integer Num is defined as the number of the use case. The number is added with a fixed prefix and appended to the variable string Str3 and the line is wrapped. Each time it is determined to be a comment, the number is increased by one, thereby achieving the purpose of adding the use case number.

[0023] Furthermore, step S5 includes the following sub-steps:

[0024] S51: If the SQL obtained from the string list List1 does not meet the judgment in step S4, it is processed as a DDL statement, and the query SQL is executed using the Statement object, and then the SQL is added with the fixed format of the DDL statement, and then appended to the variable string Str3 and wrapped;

[0025] S52: If an error occurs when executing SQL in the above steps, the error statement processing flow is performed, the error SQL is added with a fixed format and appended to the variable string Str3 and wrapped, and then the error information is obtained, and the fixed format is added and appended to the variable string Str3 and wrapped.

[0026] Furthermore, step S5 also includes the following sub-steps:

[0027] S53: Output the content of the variable string Str3 to a separate log file to obtain the use case result of converting SQL to DBFIT format.

[0028] The beneficial effects of the present invention are:

[0029] The present invention processes SQL statements through Java language and can adapt to various database types such as MySQL, Oracle, Postgres, etc. It can process query statements, DDL statements, comments, block statements, procedure functions, trigger timing jobs and other syntax types, automatically add the set corresponding format and result set, and automatically identify comments for use case numbering, process abnormal error SQL and add error information.

[0030] The present invention is different from manually written use cases. The method can automatically identify and split SQL and generate DBFIT format use cases, which greatly reduces the workload of testers, improves work efficiency, is less prone to errors, and lowers the technical threshold for use case writing. There is no need to learn the DBFIT fixed syntax format, and only requires the ability to write SQL. The automatically generated format is standardized and has a use case number for easy search. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0032] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0033] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0034] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0035] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0036] See also Figure 1 A method for quickly generating DBFIT use cases is implemented using Java language, and can convert basic SQL statements into DBFIT format use cases. The method includes the following steps:

[0037] Step 1: Read the SQL text file, use Java's file byte input stream and buffered byte input stream to read the SQL file content and append each line to a variable string Str1.

[0038] Step 2: split the SQL string. Use split and regular expressions to split the SQL content stored in the variable string Str1 obtained in step 1 using semicolons plus spaces or tabs as delimiters, and put the split results into the string array Arr1.

[0039] Step 3: block statement processing and procedure function processing. First, use the for loop to process the string array Arr1 obtained in step 2, remove the leading and trailing spaces, and then perform a sentence start judgment. If it starts with declare or begin, as well as create procedure or create function, it is determined to be a PL / SQL statement block and stored in a separate variable string Str2 until a line ending with end is matched. The PL / SQL statement block is determined to be over and the variable string Str2 is appended as a whole to the string list List1. If it is determined not to be a PL / SQL statement block, it will be directly appended to the string list List1 until all contents in the string array Arr1 are processed.

[0040] Step 4: Establish a database connection. According to the configured database connection string information, establish connections to each database and each node, and distinguish and name them for use when switching database connections.

[0041] Step 5: Node switching determination. Use a for loop to process the string list List1 obtained in step 3 and perform sentence start determination. If it starts with bind current db connect, it is considered a node switching statement. According to the number of nodes that follow, the value of the Statement object is set to the Statement object created by the corresponding node connection information to achieve the purpose of switching the node. Otherwise, it is the default node connection. Then append the current row of the string list List1 to be processed to the final result variable string Str3.

[0042] Step 6, query statement determination: after the determination in step 5, if it does not meet the switch node statement, the query statement determination is performed, that is, if the SQL obtained in the string list List1 starts with a query keyword such as select or show, it is identified as a query statement, and the query SQL is executed using the Statement object. The returned result is stored in a database result set ResultSet, and the current query statement is added with the corresponding format, and appended to the variable string Str3 and wrapped. Then, the column name is obtained from the database result set ResultSet, and all column names are formatted and appended to the variable string Str3 and wrapped. Finally, the query result is returned from the database result set ResultSet, and the fixed format is added and appended to the variable string Str3 and wrapped.

[0043] Step seven, comment information determination, if the SQL obtained from the string list List1 starts with a comment symbol such as / / or --, it is identified as comment information, and the comment information is appended to the variable string Str3 and wrapped, and then an integer Num is defined as the number of the use case, and the number is added to a fixed prefix and appended to the variable string Str3 and wrapped, and each time it is determined to be a comment, the number is increased by one, thereby achieving the purpose of adding the use case number.

[0044] Step 8, other statement processing, if the SQL obtained in the string list List1 does not meet the judgment in steps 5, 6, and 7, it is processed as a DDL statement, and the query SQL is executed using the Statement object. The SQL is then added with the fixed format of the DDL statement, and then appended to the variable string Str3 and wrapped.

[0045] Step nine, error statement processing. If an error occurs when executing SQL in the above steps, the error statement processing flow is performed. The error SQL is added with a fixed format and appended to the variable string Str3 and wrapped. Then the error information is obtained, and the fixed format is added and appended to the variable string Str3 and wrapped.

[0046] Step 10, result output, output the variable string Str3 content to a separate log file, and you can get the use case result of converting basic SQL to DBFIT format.

[0047] Based on the above embodiments, the present invention has at least the following technical effects:

[0048] The present invention processes SQL statements through Java language and can adapt to various database types such as MySQL, Oracle, Postgres, etc. It can process query statements, DDL statements, comments, block statements, procedure functions, trigger timing jobs and other syntax types, automatically add the set corresponding format and result set, and automatically identify comments for use case numbering, process abnormal error SQL and add error information.

[0049] The present invention is different from manually written use cases. The method can automatically identify and split SQL and generate DBFIT format use cases, which greatly reduces the workload of testers, improves work efficiency, is less prone to errors, and lowers the technical threshold for use case writing. There is no need to learn the DBFIT fixed syntax format, and only requires the ability to write SQL. The automatically generated format is standardized and has a use case number for easy search.

[0050] It should be noted that, for the above embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification belong to preferred embodiments, and the actions involved are not necessarily required by the present application.

[0051] The above embodiments describe the basic principles and main features of the present invention and the advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the changes and modifications made by those skilled in the art shall be within the scope of protection of the appended claims of the present invention without departing from the spirit and scope of the present invention.

Claims

1. A method to quickly generate DBFIT use cases, It is characterized in that The steps include: S1: Read SQL text file; Step S1 specifically includes: using Java's file byte input stream and buffered byte input stream to read the SQL text file content, and append each line to a variable string Str1; S2: data preprocessing, including SQL string segmentation, block statement processing, and procedure function processing; Step S2 includes the following sub-steps: S21: Split the SQL string, using split and regular expressions to split the SQL text file content stored in the variable string Str1 obtained in step S1 using semicolons plus spaces or tabs as delimiters, and put the split results into the string array Arr1; S22: looping the string array Arr1 obtained in step S21, removing the leading and trailing spaces, and then performing sentence start judgment. If it starts with declare or begin, as well as create procedure or create function, it is judged to be a PL / SQL statement block and stored in a separate variable string Str2 until a line ending with end is matched, then the PL / SQL statement block is judged to be over, and the variable string Str2 is appended as a whole to the string list List1; if it is judged not to be a PL / SQL statement block, it is directly appended to the string list List1 until all contents in the string array Arr1 are processed; S3: Establish a database; Step S3 specifically includes: establishing connections to each database and each node according to the configured database connection string information, and distinguishing and naming them for use when switching database connections; S4: using a multiple determination mechanism to perform determination, so as to achieve the purpose of adding a use case number, wherein the multiple determination mechanism includes node switching determination, query statement determination, and comment information determination; Step S4 includes the following sub-steps: S41: Node switching judgment, loop processing the string list List1 obtained in step S22, and judge the beginning of the sentence. If it starts with the switch keyword, it is considered as a node switching statement. According to the number of nodes following it, the value of the Statement object is set to the Statement object created by the corresponding node connection information to achieve the purpose of switching the node. Otherwise, it is the default node connection; then the current line of the string list List1 to be processed is appended to the final result variable string Str3; S42: Query statement determination. If the switch node statement is not met after the determination in step S41, the query statement determination is performed. If the SQL obtained in the string list List1 starts with a query keyword, it is identified as a query statement. The query SQL is executed using the Statement object. The returned result is stored in a database result set ResultSet. The current query statement is added with a corresponding format, and appended to the variable string Str3 and wrapped. Then, the column names are obtained from the database result set ResultSet. All column names are formatted and appended to the variable string Str3 and wrapped. Finally, the query results are retrieved from the database result set ResultSet, and the fixed format is added and appended to the variable string Str3 and wrapped. S5: According to the determination result of step S4, different statement processing methods are selected to process the statement, and finally a use case result in DBFIT format is obtained; Step S5 includes the following sub-steps: S51: If the SQL obtained from the string list List1 does not meet the judgment in step S4, it is processed as a DDL statement, and the query SQL is executed using the Statement object. The SQL is then added with the fixed format of the DDL statement, and then appended to the variable string Str3 and wrapped.

2. A method for quickly generating a DBFIT use case as claimed in claim 1, It is characterized in that Step S4 also includes the following sub-steps: S43: Determine the comment information. If the SQL obtained from the string list List1 starts with a comment symbol, it is considered as comment information. The comment information is appended to the variable string Str3 and the line is wrapped. Then an integer Num is defined as the number of the use case. The number is added with a fixed prefix and appended to the variable string Str3 and the line is wrapped. Each time it is determined to be a comment, the number is increased by one, thereby achieving the purpose of adding the use case number.

3. A method for quickly generating a DBFIT use case as claimed in claim 2, It is characterized in that Step S5 also includes the following sub-steps: S52: If an error occurs when executing SQL in the above steps, the error statement processing flow is performed, the error SQL is added with a fixed format and appended to the variable string Str3 and wrapped, and then the error information is obtained, and the fixed format is added and appended to the variable string Str3 and wrapped.

4. A method for rapidly generating a DBFIT use case as claimed in claim 3, It is characterized in that Step S5 also includes the following sub-steps: S53: Output the content of the variable string Str3 to a separate log file to obtain the use case result of converting SQL to DBFIT format.