Efficient PL / SQL database test case generation method and system
By performing static and dynamic analysis of PL/SQL source code and optimizing test cases with machine learning algorithms, the problems of low efficiency and difficult quality of PL/SQL code test cases are solved, and efficient and low error rate test cases are achieved.
Patent Information
- Application Number
- CN202510900947.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-07-01
AI Technical Summary
Writing and maintaining high-quality PL/SQL code test cases is a time-consuming and error-prone task, and the prior art is difficult to generate efficiently and the quality is difficult to guarantee.
By statically analyzing the PL/SQL source code, generating test case templates, and dynamically testing in simulated or real database environments, combining static and dynamic analysis results, machine learning algorithms are used to optimize test cases to generate efficient and high-quality test cases.
It significantly improves the generation efficiency and quality of PL/SQL database test cases, reduces manual intervention, reduces error rates and accelerates the development cycle.
Smart Images

Figure CN120407424A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automated testing in database management systems, and particularly relates to an efficient method and system for generating PL / SQL database test cases. Background Art
[0002] As a procedural extension language for databases, PL / SQL is widely used in data processing and business logic implementation. It combines the data operation capabilities of SQL and the logical processing capabilities of procedural programming languages, enabling developers to write complex transaction logics, data processing scripts, as well as stored procedures and functions. However, in complex application scenarios, although PL / SQL provides powerful functions, writing and maintaining high-quality PL / SQL code test cases is a time-consuming and error-prone task. Summary of the Invention
[0003] The present invention aims to solve at least one of the technical problems existing in the related art. For this purpose, the present invention provides an efficient method and system for generating PL / SQL database test cases, which significantly improves the generation efficiency and quality of PL / SQL database test cases, reduces manual intervention, lowers the error rate, and speeds up the development cycle.
[0004] The present invention provides an efficient method for generating PL / SQL database test cases, including: S1: Perform static analysis on the PL / SQL source code to obtain static analysis results; S2: Select matching predefined test case templates from a predefined test case template library according to the static analysis results, and dynamically adjust the predefined test case templates according to the PL / SQL code characteristics to obtain test case templates; S3: Perform dynamic testing according to the test case templates in a simulated or real database environment, perform execution path tracking, boundary value detection, and capture exceptions to obtain dynamic analysis results; S4: Combine the static analysis results and the dynamic analysis results to automatically generate test cases; S5: Execute the test cases, deeply analyze the test results through machine learning algorithms, and adjust the test cases through a feedback optimization mechanism according to the analysis results to obtain the final test cases.
[0005] Further, the static analysis includes lexical analysis and syntactic analysis.
[0006] Further, step S1 includes: S11: Convert the PL / SQL source code into a token stream, identify all keywords, identifiers, and operators; classify each keyword, identifier, and operator and record their position information; S12: Construct an abstract syntax tree based on keywords, identifiers, and operators; S13: Construct a control flow graph and a data flow graph based on the abstract syntax tree; S14: Construct a dependency relationship graph between functions and stored procedures based on the abstract syntax tree, control flow graph, and data flow graph.
[0007] Furthermore, the static analysis results include the position information of each keyword, identifier, and operator, the abstract syntax tree, the control flow graph, the data flow graph, and the dependency relationship graph between functions and stored procedures; The abstract syntax tree includes multiple syntax elements, and the syntax elements include variable declarations, function definitions, and loop structures. The abstract syntax tree extracts the name, type, and scope information of each syntax element; The control flow graph shows the control flow in the program; The data flow graph shows the way data flows in the program; The dependency relationship graph between functions and stored procedures identifies the parameter passing paths and records the global variables, local variables, the scope of global variables, and the scope of local variables.
[0008] Furthermore, in step S2, the test case template library includes boundary value testing, normal process testing, exception handling testing, and performance testing.
[0009] Furthermore, in step S3, In a simulated or real database environment, use the debugger API to monitor the execution of each statement in the test case template and its corresponding input and output in real time; and automatically generate an execution path report and a boundary value test plan; The execution path report includes the input and output parameter values, return values, and call order of the function; the boundary value test plan obtains boundary value test cases and boundary value prediction results; Capture and record the exception information and the location where the exception information occurs according to the execution path report and the boundary value prediction results.
[0010] Furthermore, in step S4, S41: Obtain the static analysis results and the dynamic analysis results; S42: Divide the input space according to the static analysis results and establish orthogonal classification dimensions for each parameter; S43: According to the orthogonal classification dimensions, use the Pairwise algorithm to generate a pairwise interaction coverage set and obtain the minimum test combination; S44: Automatically identify numerical or string boundaries according to the dynamic analysis results; S45: Traverse all branches of the control flow graph according to the static analysis results and dynamic analysis results, dynamically iterate to solve the execution paths of each branch, and obtain path-sensitive test cases; S46: Adopt a cross-stage coordination mechanism, synthesize the minimum test combination, numerical or string boundaries, and path-sensitive test cases, dynamically supplement and optimize the minimum test combination, and generate test cases.
[0011] Further, in step S5, S51: Execute the test cases to obtain test results; S52: Deeply analyze the test results through a machine learning algorithm to identify uncovered code paths or potential problems; S53: Adjust the test cases according to the uncovered code paths or potential problems through a feedback optimization mechanism; S54: Repeat steps S51 to S53 to obtain the final test cases.
[0012] Further, in step S53, the adjusted test cases are seamlessly integrated with the CI / CD pipeline to automatically trigger the test process.
[0013] The present invention also provides an efficient PL / SQL database test case generation system for executing the above-mentioned efficient PL / SQL database test case generation method, including: A static analysis module; the static analysis module performs static analysis on the PL / SQL source code to obtain static analysis results; A test case template acquisition module, which selects a matching predefined test case template from a predefined test case template library according to the static analysis results, and dynamically adjusts the predefined test case template according to the PL / SQL code characteristics to obtain a test case template; A dynamic analysis module, which performs dynamic testing according to the test case template in a simulated or real database environment, performs path tracking, boundary value detection, and captures exceptions; A test case generation module, which combines the static analysis results and dynamic analysis results to automatically generate test cases; A feedback optimization module, which executes the test cases, deeply analyzes the test results through a machine learning algorithm, and adjusts the test cases through a feedback optimization mechanism according to the analysis results to obtain the final test cases.
[0014] One or more of the above technical solutions in the embodiments of the present invention have at least one of the following technical effects: The present invention significantly improves the generation efficiency and quality of PL / SQL database test cases, reduces manual intervention, lowers the error rate, and speeds up the development cycle.
[0015] Additional aspects and advantages of the present invention will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0017] Figure 1 is a schematic flowchart of an efficient PL / SQL database test case generation method provided by the present invention.
[0018] Figure 2 is a schematic structural diagram of an efficient PL / SQL database test case generation system provided by the present invention.
[0019] Reference Signs: 101, static analysis module; 102, test case template acquisition module; 103, dynamic analysis module; 104, test case generation module; 105, feedback optimization module. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0020] To make the objectives, technical solutions and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall 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.
[0021] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. mean that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the embodiments 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 can be combined in a suitable manner in any one or more embodiments or examples. In addition, without conflict, those skilled in the art can combine the different embodiments or examples described in this specification and the features of the different embodiments or examples.
[0022] The following is combined withFigures 1 to 2 An efficient method and system for generating PL / SQL database test cases of the present invention are described.
[0023] As Figure 1 shown, an efficient method for generating PL / SQL database test cases includes: S1: Perform static analysis on the PL / SQL source code to obtain the static analysis result; The static analysis includes lexical analysis and syntax analysis.
[0024] Use tools such as ANTLR (Another Tool for Language Recognition) or Jison (a parser generator written in JavaScript) to perform lexical analysis and syntax analysis on the PL / SQL source code; S11: Convert the PL / SQL source code into a token stream, identify all keywords, identifiers, and operators; classify each keyword, identifier, and operator and record their location information; Keywords include SELECT, INSERT, UPDATE, etc.; identifiers include variable names and function names, etc., and operators include = and +, etc.
[0025] In some specific embodiments of the present invention, for each keyword, identifier, and operator, the system records their line numbers and column numbers in the source code and stores them in a structured data, which can be in JSON format for subsequent error location.
[0026] S12: Construct an Abstract Syntax Tree (AST) based on the keywords, identifiers, and operators; The abstract syntax tree includes multiple syntax elements. The syntax elements include variable declarations, function definitions, loop structures. The abstract syntax tree extracts the name, type, scope, etc. of each syntax element and records them in a data structure; for a variable declaration, the system not only records the name of the variable but also its data type, initial value, and scope of action.
[0027] The abstract syntax tree includes multiple nodes, and each node contains a syntax structure and the attributes of the syntax structure.
[0028] In some specific embodiments of the present invention, for example, for an assignment statement node, record the variable being assigned and the source of its value.
[0029] S13: Construct a Control Flow Graph (CFG) and a Data Flow Graph (DFG) based on the abstract syntax tree; The CFG shows the control flow in the program; the DFG shows how data flows in the program; CFG and DFG record in detail the conditional expressions and their branch paths of each control structure (such as IF statements, CASE statements, etc.), ensuring comprehensive coverage of all possible execution paths. For example, for an IF-ELSE structure, the specific content of the conditional expression will be recorded, and corresponding paths will be generated for each branch.
[0030] Automatically generate detailed documentation to explain the working principles of these logical structures, helping developers understand the code's workflow.
[0031] S14: Construct a dependency relationship graph between functions and stored procedures based on the abstract syntax tree, control flow graph, and data flow graph.
[0032] The dependency relationship graph between functions and stored procedures includes direct calls and indirect calls, identifies parameter passing paths, and understands the interactions between different parts.
[0033] Analyze the usage of global variables to ensure that all dependency relationships are correctly captured, which helps to understand the overall structure of the program and the mutual influence between its various parts.
[0034] Record the global variables, local variables used in functions and stored procedures, as well as the scopes of global variables and local variables, helping developers understand the variable scopes and lifecycles. For example, generate a variable scope graph to clearly show the usage of each variable within its scope.
[0035] Automatically extract all input parameters, output parameters, and their data type information from function or stored procedure signatures, taking into account default values, optional parameters, etc., to ensure comprehensive coverage of all possible input-output combinations.
[0036] Extract all input and output parameters of a function or stored procedure, including their data types, constraints (such as NOT NULL), and default values, to form a detailed parameter list. For example, for a stored procedure with multiple input parameters, record the data type of each parameter, whether NULL values are allowed, and whether there are default values.
[0037] The static analysis results include the location information of each keyword, identifier, and operator, the abstract syntax tree, the control flow graph, the data flow graph, and the dependency relationship graph between functions and stored procedures; The abstract syntax tree includes multiple syntax elements, and the syntax elements include variable declarations, function definitions, loop structures. Extract the name, type, and scope information for each syntax element; The dependency relationship graph between functions and stored procedures identifies parameter passing paths and records global variables, local variables, as well as the scopes of global variables and local variables.
[0038] S2: Select a matching test case template from the predefined test case template library according to the static analysis results, and dynamically adjust the test case template according to the PL / SQL code characteristics to obtain a test case template; The predefined test case template library contains various types of predefined test case templates. The predefined test case templates include boundary value testing, normal process testing, exception handling testing, performance testing, etc. Each test case template has a detailed description explaining the applicable scenarios and expected results.
[0039] When designing the test case templates, various common programming patterns and best practices are considered to ensure that the requirements in most cases can be met. For example, add length limit testing for string operations and overflow testing for numerical calculations.
[0040] Each test case template is accompanied by a detailed usage guide to instruct users on how to adjust the template content according to specific requirements. For example, for the boundary value test template, specific suggestions on how to select appropriate boundary values are provided.
[0041] Dynamically adjust the template content according to the specific PL / SQL code characteristics (such as the specific functions used, the data types involved, etc.). For example, add a dedicated date format test case for code involving date operations.
[0042] Automatically select a suitable template according to the static analysis results and allow users to manually adjust the template to better meet specific requirements. Provide a visual editor that enables users to easily modify the test case template. For example, users can quickly adjust the test steps in the template by dragging and dropping components.
[0043] Automatically generate a preliminary test case template and provide intelligent prompts to help users complete the template content. For example, when it is detected that a certain variable may be sensitive data, prompt the user to add corresponding security test steps.
[0044] Select a matching predefined test case template from the predefined test case template library according to the static analysis results, and dynamically adjust the test case template according to the PL / SQL code characteristics to obtain a test case template.
[0045] S3: Conduct dynamic testing according to the test case template in a simulated or real database environment, perform path tracking, boundary value detection, and capture exceptions to obtain dynamic analysis results; In a simulated or real database environment, use the debugger API to monitor the execution status of each statement in the test case template and its corresponding input and output in real time; The information collected includes but is not limited to the current values of variables, the jump conditions of the control flow, etc.; Support multi-version database environments to ensure the consistency and reliability of test results. For example, before each execution, automatically detect the version of the target database and adjust the test strategy accordingly; Record the input and output parameter values of each function call to help understand the program behavior. The system will also generate detailed log files to record all important events and state changes; Automatically generate an execution path report. The execution path report includes the input and output parameter values, return values, and call order of functions; it helps developers deeply understand the actual execution of the program.
[0046] Automatically generate boundary value test plans to obtain boundary value test cases and boundary value prediction results; automatically generate a series of boundary value test cases to ensure that each variable is fully tested within its legal range. For example, for integer types, generate test cases such as the minimum value -1, the minimum value, the minimum value + 1, the maximum value - 1, the maximum value, the maximum value + 1, etc.
[0047] Pay special attention to the boundary conditions of variable values to ensure coverage of all possible input ranges. For example, for numeric variables, in addition to considering their maximum and minimum values, also consider the cases close to these two extreme values.
[0048] Automatically generate a detailed boundary value test plan, listing the boundary value test cases for each variable and their expected results. For example, for a form with an age field, the system will generate test cases such as age 0, age 1, age at the maximum value, age at the maximum value + 1, etc.
[0049] Capture and record exception information and the location where the exception information occurs based on the execution path report and boundary value prediction results. Capture and record all thrown exceptions and their occurrence locations to help generate more targeted test cases. For uncaught exceptions, provide potential repair suggestions.
[0050] Exception information will be recorded in detail, including stack traces, error messages, etc., so that developers can quickly locate problems. In addition, automatically analyze the cause of the exception and propose improvement suggestions. For example, when detecting that an exception is caused by a null pointer reference, it is recommended to add null value checks.
[0051] Automatically generate a detailed exception report, listing the occurrence location, stack trace, and recommended repair measures for each exception. This helps developers quickly fix problems in the code.
[0052] S4: Combine the static analysis results and dynamic analysis results to automatically generate test cases; S41: Obtain the static analysis results and dynamic analysis results; Upload the PL / SQL script file through an intuitive and easy-to-use graphical user interface (GUI), configure the test requirements (such as the expected code coverage, whether to enable advanced analysis options, etc.), and obtain the static analysis results and dynamic analysis results.
[0053] The GUI interface supports users to view and edit the generated test cases.
[0054] The GUI has a good user experience design, enabling non-technical personnel to easily get started; the GUI provides rich documentation and examples to help users understand how to use the tool. The GUI interface supports drag-and-drop file upload, simplifying user operations. The GUI provides detailed configuration options, allowing users to flexibly set test parameters according to project requirements. For example, users can select different test coverage criteria (such as 80%, 90%, etc.), or choose whether to enable advanced options such as performance testing and security testing.
[0055] S42: Divide the input space according to the static analysis results, and establish orthogonal classification dimensions for each parameter; In some specific embodiments of the present invention, the classification tree method (CTM) is used to divide the input space, and orthogonal classification dimensions are established for each parameter.
[0056] S43: According to the orthogonal classification dimensions, use the Pairwise (pairwise comparison / operation) algorithm to generate a pairwise interaction coverage set and obtain the minimum test combination; In some specific embodiments of the present invention, PICT (Pairwise Independent Combinatorial Testing) is used to generate the minimum test combination, and the combinations with constraint conflicts are automatically filtered.
[0057] S44: Automatically identify the numerical or string boundaries according to the dynamic analysis results; S45: Traverse all branches of the control flow graph according to the static analysis results and dynamic analysis results, dynamically iterate to solve the execution path of each branch, and obtain path-sensitive test cases; In some specific embodiments of the present invention, traverse all branch nodes of the control flow graph, convert the IF / WHILE conditions into logical expressions, record the path constraints in the SMT-LIB format, use Z3 to dynamically solve the values that satisfy the constraints, skip the unreachable paths, and finally generate an input set that satisfies different branch conditions. Repeat this process to obtain path-sensitive test cases.
[0058] S46: Adopt a cross-stage coordination mechanism to comprehensively combine the minimum test combination, numerical or string boundaries, and path-sensitive test cases, dynamically supplement and optimize the minimum test combination, and generate test cases.
[0059] In some specific embodiments of the present invention, a cross-stage coordination mechanism is adopted. The input constraints are passed to the path condition solving, the covered paths are dynamically counted, and the generation of supplementary test cases is guided. The coverage matrix is used to optimize the combination to generate test cases. After the generated test cases are automatically executed, it is verified whether the actual output matches the expectation, and the failed test cases are traced back to the corresponding stage to adjust the generation strategy.
[0060] Combining the static analysis results and the dynamic analysis results, test cases are automatically generated through the GUI. The entire process from uploading the code to generating test cases is fully automated, and users can complete complex tasks with simple operations. A series of predefined tasks, such as static analysis, dynamic analysis, etc., are run in the background and the user is notified after completion. The current task completion percentage is displayed through a real-time progress bar, and a detailed test progress report is automatically generated, listing the completion time of each stage, the number of problems found, and the recommended solutions. This helps the team to timely understand the test progress and take necessary actions, and at the same time provides a detailed error report when errors occur.
[0061] S5: Execute the test cases, deeply analyze the test results through machine learning algorithms, and adjust the test cases through the feedback optimization mechanism according to the analysis results; S51: Execute the test cases to obtain the test results; S52: Deeply analyze the test results through machine learning algorithms to identify uncovered code paths or potential problems; By comparing the actual output with the expected result, the difference points are found and the impacts of these problems are evaluated. The result analysis is not limited to a simple success / failure judgment, but also includes the evaluation of performance indicators, resource consumption, etc. For example, analyze the memory usage, CPU occupancy rate, etc. A detailed test result analysis report is automatically generated, listing the comparison of the actual output and the expected output of each test case, and any problems found. For example, for a performance test case, the system will analyze its execution time and resource consumption and give optimization suggestions.
[0062] The machine learning algorithms include decision trees and K-Means; the decision tree quickly classifies the test results through rule matching, such as distinguishing SQL injection risks and data type conversion errors; K-Means clusters similar failed test cases, such as all phenomena of stored procedure crashes caused by "null value passing".
[0063] S53: Adjust the test cases through the feedback optimization mechanism according to the uncovered code paths or potential problems; the adjusted test cases are seamlessly integrated with the CI / CD pipeline to automatically trigger the test process.
[0064] Continuously optimize the test strategy based on the analysis results. For example, increase the test intensity of certain key points or adjust the priority of test cases. At the same time, the system will also predict possible future problems based on historical data and take preventive measures in advance.
[0065] The system will automatically adjust the test plan according to the test results, automatically generate an optimized test plan, list the new priorities and execution orders of each test case, and improve the test efficiency and accuracy. For example, for code segments that frequently have problems, increase the test frequency and coverage to more effectively allocate resources and improve the test efficiency.
[0066] The adjusted test cases are seamlessly integrated with the existing CI / CD pipeline to ensure that a new round of tests is automatically triggered every time the code changes. This can ensure that the code quality is always at a high level.
[0067] Support integration with mainstream version control systems (such as Git) to achieve automated code synchronization and test triggering. When the code is committed, the test process is automatically started, and a detailed CI / CD integration report is automatically generated, listing the test results, discovered problems, and recommended repair measures for each code commit, and the results are fed back to the development team.
[0068] S54: Repeat steps S51 to S53 to obtain the final test cases.
[0069] Verify the efficiency and quality differences between the present invention and traditional manually written test cases through experiments. For 10 real PL / SQL stored procedures, three groups of developers respectively used the method of the present invention and traditional manually written test cases for two hours of storage, and evaluated the code coverage rate, defect discovery rate, and test case generation time. The experimental data is shown in Table 1. Table 1 Experimental data As can be seen from Table 1, the test case generation speed of the method of the present invention is 4.4 times that of manual writing. The present invention has a significant effect in shortening the test case generation time, greatly improving the efficiency. Forty-one percent more logical errors can be discovered through the branch coverage rate, and the boundary-related defect discovery rate is increased by 100%. The method of the present invention automatically generates 27 abnormal test cases not considered manually. Compared with the traditional manual writing method, the integrity and maintainability of the test cases of the method of the present invention are significantly improved.
[0070] As Figure 2 shown, an efficient PL / SQL database test case generation system is used to execute an efficient PL / SQL database test case generation method, including: The static analysis module 101 performs static analysis on the PL / SQL source code to obtain the static analysis results; The test case template acquisition module 102 selects a matching predefined test case template from the predefined test case template library according to the static analysis result, and dynamically adjusts the predefined test case template according to the PL / SQL code characteristics to obtain a test case template; The dynamic analysis module 103 performs dynamic testing according to the test case template in a simulated or real database environment, executes path tracking, boundary value detection, and captures exceptions; The test case generation module 104 automatically generates test cases by combining the static analysis result and the dynamic analysis result; The feedback optimization module 105 executes the test cases, deeply analyzes the test results through a machine learning algorithm, and adjusts the test cases through a feedback optimization mechanism according to the analysis results to obtain the final test cases.
[0071] Through the collaborative work of the above modules, by using tools such as ANTLR or Jison for lexical and syntactic analysis, and constructing an abstract syntax tree, a control flow graph, and a data flow graph, the logical structure, control flow, and data flow in the code can be automatically identified, reducing the workload of manual analysis and improving the accuracy and efficiency of analysis.
[0072] Based on the static analysis result, select the most suitable template from the predefined test case template library, and allow users to adjust according to specific requirements. This intelligent matching and adaptive customization mechanism greatly simplifies the test case design process, while ensuring the effectiveness and pertinence of the test cases.
[0073] By paying special attention to the boundary conditions of variable values and generating a series of boundary value test cases, ensure that each variable is fully tested within its legal range. In addition, the dynamic analysis module can capture and record all thrown exceptions and their occurrence locations, helping developers quickly locate potential problems and improve the quality and stability of the code. Construct a call relationship graph between functions and stored procedures, clarify the parameter passing path, and understand the interaction between different parts, which helps to more deeply understand the overall structure of the program and the mutual influence between its parts, so as to better design test cases and ensure comprehensive coverage of the entire system. Provide an intuitive and easy-to-use graphical user interface (GUI), allowing users to easily upload PL / SQL script files, configure test requirements, and view and edit the generated test cases. The GUI greatly reduces the user's usage threshold, and even non-technical personnel can quickly get started. The entire process from code upload to test case generation is fully automated, and users can complete complex tasks with simple operations. Functions such as progress tracking and error recovery ensure that the test task can be successfully completed even when problems are encountered, improving work efficiency.
[0074] Use machine learning algorithms to deeply analyze the results of each test, identify potential problem areas, and continuously optimize the test strategy based on the analysis results. This not only helps to immediately fix existing problems but also predict possible future problems and take preventive measures in advance to further improve product quality.
[0075] Seamlessly integrate with the CI / CD pipeline to achieve automated code synchronization and test triggering. When code is committed, the test process is automatically started, and the results are fed back to the development team to ensure that the code quality always remains at a high level.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or equivalently replace some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An efficient method for generating PL / SQL database test cases, characterized in that, Including: S1: Perform static analysis on the PL / SQL source code to obtain static analysis results; S2: Select matching predefined test case templates from a predefined test case template library according to the static analysis results, and dynamically adjust the predefined test case templates according to the PL / SQL code characteristics to obtain test case templates; S3: Perform dynamic testing according to the test case templates in a simulated or real database environment, perform path tracking, boundary value detection, and capture exceptions to obtain dynamic analysis results; S4: Combine the static analysis results and the dynamic analysis results to automatically generate test cases; S5: Execute the test cases, deeply analyze the test results through machine learning algorithms, and adjust the test cases through a feedback optimization mechanism according to the analysis results to obtain the final test cases.
2. An efficient PL / SQL database test case generation method according to claim 1, characterized in that, The static analysis includes lexical analysis and syntactic analysis.
3. An efficient PL / SQL database test case generation method according to claim 1, characterized in that, Step S1 includes: S11: Convert the PL / SQL source code into a token stream, identify all keywords, identifiers, and operators; classify each keyword, identifier, and operator and record their position information; S12: Construct an abstract syntax tree based on the keywords, identifiers, and operators; S13: Construct a control flow graph and a data flow graph based on the abstract syntax tree; S14: Construct a dependency relationship graph between functions and stored procedures based on the abstract syntax tree, control flow graph, and data flow graph.
4. An efficient PL / SQL database test case generation method according to claim 3, characterized in that, The static analysis results include the position information of each keyword, identifier, and operator, the abstract syntax tree, the control flow graph, the data flow graph, and the dependency relationship graph between functions and stored procedures; The abstract syntax tree includes multiple syntax elements, and the syntax elements include variable declarations, function definitions, and loop structures. The abstract syntax tree extracts the name, type, and scope information of each syntax element; The control flow graph shows the control flow in the program; The data flow graph shows the way data flows in the program; The dependency relationship graph between functions and stored procedures identifies the parameter passing path and records the global variables, local variables, and the scope of global variables and the scope of local variables.
5. An efficient PL / SQL database test case generation method according to claim 1, characterized in that In step S2, the test case template library includes boundary value testing, normal process testing, exception handling testing, and performance testing.
6. An efficient PL / SQL database test case generation method according to claim 1, characterized in that In step S3, In a simulated or real database environment, use the debugger API to monitor the execution of each statement of the test case template and its corresponding input and output in real time; And automatically generate an execution path report and a boundary value test plan; The execution path report includes the input and output parameter values, return values, and call order of the function; for the boundary value test plan, obtain boundary value test cases and boundary value prediction results; Capture and record exception information and the location where the exception information occurs according to the execution path report and the boundary value prediction results.
7. According to an efficient PL / SQL database test case generation method as described in claim 1, step S4 includes: S41: Obtain the static analysis results and the dynamic analysis results; S42: Divide the input space according to the static analysis results, and establish orthogonal classification dimensions for each parameter; S43: Generate pairwise interaction coverage sets using the Pairwise algorithm according to the orthogonal classification dimension to obtain the minimum test combination; S44: Automatically identify numerical or string boundaries based on the dynamic analysis results; S45: Traverse all branches of the control flow graph according to the static analysis results and dynamic analysis results, dynamically iterate to solve the execution path of each branch, and obtain path-sensitive test cases; S46: Adopt a cross-stage coordination mechanism to comprehensively combine the minimum test combination, numerical or string boundaries, and path-sensitive test cases, dynamically supplement and optimize the minimum test combination, and generate test cases.
8. For an efficient PL / SQL database test case generation method according to claim 1, in step S5, S51: Execute the test cases to obtain test results; S52: Deeply analyze the test results through a machine learning algorithm to identify uncovered code paths or potential problems; S53: Adjust the test cases according to the uncovered code paths or potential problems through a feedback optimization mechanism; S54: Repeat steps S51 to S53 to obtain the final test cases.
9. For an efficient PL / SQL database test case generation method according to claim 8, in step S53, the adjusted test cases are seamlessly integrated with the CI / CD pipeline to automatically trigger the test process.
10. An efficient PL / SQL database test case generation system, characterized in that, An apparatus for executing an efficient PL / SQL database test case generation method according to any one of claims 1 to 9, comprising: A static analysis module; the static analysis module performs static analysis on the PL / SQL source code to obtain static analysis results; A test case template acquisition module, the test case template acquisition module selects a matching predefined test case template from a predefined test case template library according to the static analysis results, and dynamically adjusts the predefined test case template according to the PL / SQL code characteristics to obtain a test case template; A dynamic analysis module, the dynamic analysis module performs dynamic testing according to the test case template in a simulated or real database environment, performs path tracking, boundary value detection, and captures exceptions; A test case generation module, the test case generation module automatically generates test cases by combining the static analysis results and the dynamic analysis results; A feedback optimization module, the feedback optimization module executes the test cases, deeply analyzes the test results through a machine learning algorithm, and adjusts the test cases through a feedback optimization mechanism according to the analysis results to obtain the final test cases.
Citation Information
Patent Citations
Test case automatic generation method, system and device and readable storage medium
CN116909915A
Automatic test case generation platform
CN117112400A
Code analysis optimization method and device, computer equipment and storage medium
CN118132424A
Automatic test case generation method based on large model and particle swarm optimization
CN119271565A
Automatic test case generation and execution method and system
CN119645881A
Cited By
Method and system for quickly generating and automatically testing application based on low-code platform
CN122240492A