Unit test case generation system based on large language model

By combining function dependency analysis and large language model, high-quality test cases are automatically generated, which solves the problem of relying on manual writing and low coverage in the existing technology, and achieves efficient and comprehensive test case generation.

CN119105965APending Publication Date: 2024-12-10SHANGHAI ANBAN INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411212483.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-10

Smart Images

  • Figure CN119105965A_ABST
    Figure CN119105965A_ABST
Patent Text Reader

Abstract

The invention provides a unit test case generation system based on a large language model, and the system comprises a function dependency analysis engine module which is used for preprocessing a target project, extracting a function dependency relationship, and generating an abstract syntax tree and a source code file; the large model module is used for automatically generating a test case through the code context information and the optimized cue word; and the verification and optimization module is used for verifying whether the test cases can be successfully executed or not by compiling and running the test cases, marking part of the test cases needing to be further processed, automatically analyzing error reasons, optimizing cue words and realizing automatic repair of the part of the test cases. According to the unit test case generation system based on the large language model, the function dependency analysis and the large language model are combined, the high-quality test case can be automatically generated, dependence on manpower or existing test cases is not needed, manual intervention is reduced, and the test efficiency and comprehensiveness are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiment of the present invention relates to the field of software development security technology, and in particular to a unit test case generation system based on a large language model. Background Art

[0002] Existing technologies and solutions for generating test cases mainly rely on manual generation or previously written test cases, which is very inefficient. Some large code models can generate unit test cases, but the generated test cases cannot be directly compiled and run. They still need manual judgment and modification, which has high labor costs and is difficult to achieve high coverage.

[0003] The existing technology mainly has the following problems: 1. Reliance on manually written and modified test cases: Existing technologies often require developers to manually write initial test cases, or use currently used test cases as the basis for subsequent automated generation. This reliance brings many problems. First, developers need to invest a lot of time and energy in manually writing test cases, which increases the development cycle and resource consumption. In addition, manually written test cases may have omissions or be incomplete, and cannot ensure that all code paths are fully tested. Especially in complex code structures, manually generated test cases are difficult to cover all possible execution paths. Finally, manually written test cases are easily affected by the subjective judgment of developers, and may ignore certain potential errors or boundary conditions, thus affecting the accuracy and effectiveness of the test.

[0004] 2. Generated test cases cannot improve coverage: If the existing test cases have insufficient coverage, the newly generated test cases will also be difficult to significantly improve coverage. For new test scenarios that have never been seen before, the automatically generated test cases have limited effect and are difficult to fully cover all paths and logic of the code. In addition, relying on existing test cases for expansion may inherit their deficiencies, resulting in the newly generated test cases also being unable to fully test the code.

[0005] Among the existing solutions, the Chinese patent with publication number CN113297061A introduces a method for generating test cases through feature matching. This method extracts the features of online test data and matches these features with the features of generated offline test cases, thereby determining similar offline test cases and making adjustments. However, this method relies on the quality and coverage of existing offline test cases, and the generated test cases may not necessarily improve the coverage, and cannot truly solve the above-mentioned current problems.

[0006] Therefore, it is necessary to provide a unit test case generation system based on a large language model to solve the above problems. Summary of the invention

[0007] The present invention provides a unit test case generation system based on a large language model, which can automatically generate high-quality test cases by combining function dependency analysis with a large language model, without relying on manual or existing test cases, thus reducing manual intervention and improving test efficiency and comprehensiveness.

[0008] An embodiment of the present invention provides a unit test case generation system based on a large language model, comprising: Function dependency analysis engine module, which is used to preprocess the target project, extract function dependencies, and generate abstract syntax trees and source code files; The large model module is used to automatically generate test cases based on code context information and optimized prompt words; The verification and optimization module is used to verify whether the test case can be successfully executed by compiling and running it, marking some test cases that need further processing, automatically analyzing the cause of the error, optimizing the prompt words, and realizing automatic repair of the part of the test case.

[0009] Preferably, the functional dependency analysis engine module includes: The source code preprocessing unit is used to obtain a complete source code list, read the source code directory one by one, and ensure that all functions / classes / project files to be analyzed have been correctly obtained and preprocessed through error checking and generating error logs, providing a basis for subsequent dependency analysis.

[0010] Preferably, the functional dependency analysis engine module further includes: Source code structure analysis unit, which is used for lexical analysis, syntax analysis and semantic analysis; The lexical analysis includes: converting the source code into a series of word symbols, removing comments and extra spaces, and converting constants from strings to binary form; The grammatical analysis includes: constructing a grammatical tree through recursive descent analysis and predictive analysis, and checking whether it complies with grammatical rules; The semantic analysis includes: type checking, symbol parsing, semantic checking and error handling.

[0011] Preferably, the functional dependency analysis engine module further includes: The dependency extraction and analysis unit is used to find the dependent function set of a function, process the calling relationship between functions, and through a recursive method, gradually analyze all the function sets called by the initial function to build a complete function dependency graph.

[0012] Preferably, the functional dependency analysis engine module further includes: The abstract syntax tree generation unit is used to construct an abstract syntax tree, which describes the composition and dependency relationships of various classes, objects, functions, variables and other members in the source code through lexical analysis and syntax analysis.

[0013] Preferably, the functional dependency analysis engine module further includes: The data conversion and output unit is used to convert the analysis results into vector data, and generate the source code file for each function and its dependent function set according to the extracted dependency relationship.

[0014] Preferably, the large model module includes: A prompt word tuning unit, which is used to interact with the function dependency analysis engine module, obtain the source code file, dynamically adjust and optimize the prompt word according to the source code file; use the generated test cases and their effects for feedback iteration, and adopt chain thinking strategy and analogy prompt strategy to improve the prompt word generation and optimization process; The chain thinking strategy breaks down a big problem into small problems and solves them step by step. By combining text and code together, the semantic relationship between text and code can be better understood. The analogy prompt strategy makes inferences by listing relevant cases, thereby improving the quality of the content generated by the subsequent large model.

[0015] Preferably, the large model module further includes: A large model generates test case unit, which is used to generate test cases using the large model according to the requirements of the prompt words and the source code files; The optimized prompt words and source code files are input into the big model, which has a deep understanding of the input content and logical path. During the generation process, the big model integrates the contextual information of the code and generates test cases that can fully test each part of the code.

[0016] Preferably, the verification and optimization module includes: The compilation and running verification unit is used to compile and run the generated test cases to verify whether the test cases can be successfully executed. For the compiled test cases, they are directly saved and displayed on the front end to provide support for the user's subsequent unit testing.

[0017] Preferably, the verification and optimization module further includes: The automatic repair unit is used to analyze the error causes of test cases that cannot be compiled based on compilation information, source code information, and prompt word content, further optimize the prompt words based on the error causes, and use the large model to repair the test case again.

[0018] The completion unit is used to simulate the execution of a program by using abstract symbols instead of specific values, reveal the execution path of the program, and generate corresponding input conditions for a specific program path.

[0019] Compared with the prior art, the technical solution of the embodiment of the present invention has the following beneficial effects: The unit test case generation system based on the large language model provided by the embodiment of the present invention includes: a function dependency analysis engine module, which is used to preprocess the target project, extract the function dependency relationship, and generate an abstract syntax tree and a source code file; a large model module, which is used to automatically generate test cases through code context information and optimized prompt words; a verification and optimization module, which is used to verify whether the test case can be successfully executed by compiling and running the test case, marking part of the test case that needs further processing, automatically analyzing the cause of the error, optimizing the prompt words, and realizing automatic repair of the part of the test case. By combining the function dependency analysis with the large language model, high-quality test cases can be automatically generated without relying on manual or existing test cases, thereby reducing manual intervention; Furthermore, the functional dependency analysis engine module also includes a source code structure analysis unit, which is used for lexical analysis, grammatical analysis and semantic analysis; the lexical analysis includes: converting the source code into a series of word symbols, deleting comments and redundant spaces, and converting constants from character strings to binary form; the grammatical analysis includes: constructing a syntax tree through recursive descent analysis and predictive analysis, and checking whether it complies with grammatical rules; the semantic analysis includes: performing type checking, symbol parsing, semantic checking and error handling, so as to ensure that the context-related attributes of the program code are correct and generate corresponding error messages; Furthermore, the large model module includes: a prompt word tuning unit, which is used to interact with the function dependency analysis engine module, obtain the source code file, and dynamically adjust and optimize the prompt word according to the source code file; use the generated test cases and their effects for feedback iteration, and adopt chain thinking strategy and analogy prompt strategy to improve the prompt word generation and optimization process; The chain thinking strategy breaks down a big problem into small problems and solves them step by step. By combining text and code, the semantic relationship between text and code can be better understood. The analogy prompt strategy makes inferences by listing relevant cases, which improves the quality of subsequent large model generated content and generates high-quality test cases. Furthermore, the big model module also includes: a big model test case generation unit, which is used to generate test cases using the big model according to the requirements of the prompt words and the source code files; the optimized prompt words and source code files are input into the big model, and the big model has a deep understanding of the input content and logical path; during the generation process, the big model integrates the context information of the code to generate test cases that can fully test each part of the code, thereby being able to efficiently generate comprehensive, high-quality test cases and improve testing efficiency and effectiveness. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are some embodiments of the present invention, not all embodiments. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.

[0021] Figure 1 A schematic diagram of the structure of a unit test case generation system based on a large language model provided by an embodiment of the present invention; Figure 2 A schematic diagram of the structure of a function dependency analysis engine module of a unit test case generation system based on a large language model provided by an embodiment of the present invention; Figure 3 A schematic diagram of the structure of a large model module of a unit test case generation system based on a large language model provided by an embodiment of the present invention; Figure 4 A schematic diagram of the structure of a verification and optimization module of a unit test case generation system based on a large language model provided by an embodiment of the present invention; Figure 5 A flowchart of a method for using a unit test case generation system based on a large language model is provided for one embodiment of the present invention. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0023] The technical solution of the present invention is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0024] Based on the problems existing in the prior art, an embodiment of the present invention provides a unit test case generation system based on a large language model. By combining function dependency analysis with a large language model, high-quality test cases can be automatically generated without relying on manual or existing test cases, thereby reducing manual intervention and improving test efficiency and comprehensiveness.

[0025] Figure 1A schematic diagram of a unit test case generation system based on a large language model is provided for one embodiment of the present invention. Figure 1 , an embodiment of the present invention provides a unit test case generation system based on a large language model, comprising: Function dependency analysis engine module, which is used to preprocess the target project, extract function dependencies, and generate abstract syntax trees and source code files; The large model module is used to automatically generate test cases based on code context information and optimized prompt words; The verification and optimization module is used to verify whether the test case can be successfully executed by compiling and running it, marking some test cases that need further processing, automatically analyzing the cause of the error, optimizing the prompt words, and realizing automatic repair of the part of the test case.

[0026] Specifically, the function dependency analysis engine module plays a key basic role in the entire unit test case generation task, and finally generates a self-complete source code file so that subsequent modules can effectively generate high-quality unit test cases. The source code file includes a C source code file or a C++ source code file.

[0027] The large model module ensures that the generated unit test cases can fully and accurately cover the main functions and logical paths of the code. Through dynamic adjustment and iterative optimization, the generation strategy is continuously improved, which can effectively improve the efficiency of test case generation and the quality of test cases, and provide support for the code coverage of unit tests and the efficiency and comprehensiveness of tests.

[0028] The verification and optimization module automatically generates test cases for parts not covered by the test cases generated by the large model through technologies such as symbolic execution, and further improves and adjusts them in combination with manual optimization to ensure that the test cases can cover all possible code paths and logical structures.

[0029] Figure 2 A schematic diagram of the structure of a functional dependency analysis engine module of a unit test case generation system based on a large language model provided by an embodiment of the present invention. Figure 2 The function dependency analysis engine module implements a series of steps such as source code preprocessing, source code structure analysis, dependency extraction and analysis, abstract syntax tree generation, data conversion and output to achieve comprehensive parsing of C / C++ code and accurate extraction of dependency relationships, providing high-quality input data for subsequent modules. The function dependency analysis engine module includes: The source code preprocessing unit is used to obtain a complete source code list, read the source code directory one by one, and ensure that all functions / classes / project files to be analyzed have been correctly obtained and preprocessed through error checking and generating error logs, providing a basis for subsequent dependency analysis.

[0030] In a specific implementation, the functional dependency analysis engine module further includes: Source code structure analysis unit, which is used for lexical analysis, syntax analysis and semantic analysis; The lexical analysis includes: converting the source code into a series of word symbols, removing comments and extra spaces, and converting constants from strings to binary form; The grammatical analysis includes: constructing a grammatical tree through recursive descent analysis and predictive analysis, and checking whether it complies with grammatical rules; The semantic analysis includes: type checking, symbol parsing, semantic checking and error handling.

[0031] In a specific implementation, the functional dependency analysis engine module further includes: The dependency extraction and analysis unit is used to find the dependent function set of a function, process the calling relationship between functions, and gradually analyze all the function sets called by the initial function through a recursive method to build a complete function dependency graph. When processing dependencies between functions, this unit can detect and process dependency loops to avoid endless recursive processes. In addition, this unit also analyzes the dependency relationship between functions and types and global variables to ensure the integrity of the dependency relationship.

[0032] In a specific implementation, the functional dependency analysis engine module further includes: The abstract syntax tree generation unit is used to build an abstract syntax tree. Through lexical analysis and syntax analysis, it describes the composition and dependency relationships of various classes, objects, functions, variables and other members in the source code. The abstract syntax tree shields the specific details of the code, makes the member relationship clearer, reduces the size of the syntax tree, and improves storage and query efficiency. Through the generation and optimization of the abstract syntax tree, the clarity of the code structure and storage efficiency are ensured.

[0033] In a specific implementation, the functional dependency analysis engine module further includes: The data conversion and output unit is used to convert the analysis results into vector data, and generate the source code files for each function and its dependent function set according to the extracted dependencies. It ensures that the source code files can be compiled and executed independently. These source code files will be used as input data for the large model to ensure that the large model can obtain comprehensive and accurate input data.

[0034] Figure 3 A schematic diagram of the structure of a large model module of a unit test case generation system based on a large language model is provided for one embodiment of the present invention. Figure 3The large model module is the core module of this system. It automatically generates test cases and can solve the problem of test cases relying on manual writing and low coverage through continuous prompt word tuning and post-tuning operations. The large model module includes: The prompt word tuning unit is used to interact with the function dependency analysis engine module, obtain the source code file, and dynamically adjust and optimize the prompt word according to the source code file; use the generated test cases and their effects for feedback iteration, and adopt chain thinking strategy and analogy prompt strategy to improve the prompt word generation and optimization process; automatically generate high-quality prompt words by analyzing the code and historical test cases, reduce manual intervention, and improve the efficiency and accuracy of prompt word generation. Use artificial intelligence models to evaluate the prompt word effect, optimize the prompt word generation strategy according to the evaluation results, and ensure that the prompt word can guide the large model to generate high-quality test cases.

[0035] The chain thinking strategy breaks down a big problem into small problems and solves them step by step. By combining text and code together, the semantic relationship between text and code can be better understood. The analogy prompt strategy makes inferences by listing relevant cases, thereby improving the quality of the content generated by the subsequent large model.

[0036] In a specific implementation, the large model module also includes: A large model generates test case unit, which is used to generate test cases using the large model according to the requirements of the prompt words and the source code files; The optimized prompt words and source code files are input into the big model, which has a deep understanding of the input content and logical path. During the generation process, the big model integrates the contextual information of the code and generates test cases that can fully test each part of the code.

[0037] The large model checks the generated test cases, evaluates their logical and grammatical correctness, and rewrites and fixes errors to increase the probability of successful compilation. Based on the results of the preliminary inspection and error information, this unit will continuously perform iterative optimization and adjust the generation strategy. Through this process, comprehensive and high-quality test cases can be efficiently generated, which greatly reduces manual intervention and improves test efficiency and effectiveness.

[0038] Figure 4 A schematic diagram of the structure of a verification and optimization module of a unit test case generation system based on a large language model provided by an embodiment of the present invention. Figure 4 The verification and optimization module is responsible for fully verifying, repairing and completing the generated test cases to ensure that the generated test cases can be successfully compiled and run. The verification and optimization module includes: The compilation and running verification unit is used to compile and run the generated test cases to verify whether the test cases can be successfully executed. For the compiled test cases, they are directly saved and displayed on the front end to provide support for the user's subsequent unit testing. For the test cases that cannot be run, the subsequent units will do further processing.

[0039] In a specific implementation, the verification and optimization module also includes: The automatic repair unit is used to analyze the error causes of test cases that cannot be compiled based on compilation information, source code information, and prompt word content, further optimize the prompt words based on the error causes, and use the large model to repair the test case again.

[0040] The completion unit is used to simulate the execution of the program by using abstract symbols instead of specific values, revealing the execution path of the program and generating corresponding input conditions for a specific program path. This method can automatically generate test cases to complete the parts not covered by the test cases generated by the large model. Finally, for some very complex functions, a small amount of manual judgment and adjustment is required.

[0041] Figure 5 A flowchart of a method for using a unit test case generation system based on a large language model is provided for one embodiment of the present invention. Figure 5 ,The method of using the unit test case generation system based on the large language model is as follows: 1) Create a task. The user creates a new task and imports the project files to be tested or uploads the code repository address, including all necessary files related to the project such as source code files.

[0042] 2) Source code preprocessing: The system preprocesses the imported source code to check the integrity and correctness of the source code. If the preprocessing fails, the process will generate a processing failure code and terminate; if successful, it will proceed to the next step.

[0043] 3) Source code structure analysis: The system performs structural analysis on the source code, including lexical analysis, syntax analysis, and semantic analysis, generates an abstract syntax tree, and extracts code structure and logic information.

[0044] 4) Dependency extraction and analysis: extract the dependencies of functions and related elements in the code, generate function and file-level dependency graphs, and ensure a comprehensive understanding of the code's dependency structure.

[0045] 5) Abstract syntax tree generation: Based on the dependency analysis results, an abstract syntax tree is generated to describe the composition and dependency relationships of each class, object, function, variable and other member in the source code.

[0046] 6) Data conversion and output: The system converts the analysis results and dependencies into vector data, outputs them as input data required for large model training and test case generation, and generates a self-complete source code file for each function and its dependent function set.

[0047] 7) Prompt word tuning: Based on the data and analysis results generated in the previous steps, the system optimizes the prompt words. Through feedback, iterative optimization and evaluation, it ensures the generation of high-quality prompt words and guides the large model to generate high-quality test cases.

[0048] 8) The big model generates test cases. The optimized prompt words and source code data are input into the big model. The big model generates test cases covering the main functions and logical paths, and performs a preliminary check on the generated test cases to ensure that the logic is correct, there are no syntax errors, and that they can be successfully compiled.

[0049] 9) Compile and run to verify whether the generated test cases can run successfully, and mark the parts that need further processing.

[0050] 10) Analyze the reasons why the test fails to run successfully, further optimize the prompt words, and use the large model to automatically repair the test cases that fail to run successfully.

[0051] 11) Improve and complete, automatically generate test cases to complete the parts not covered by the test cases generated by the large model, and further improve and adjust the generated test cases to ensure that the test cases cover all possible code paths and logical structures.

[0052] 12) The generation task is completed. If the generated test cases meet the expected quality standards and can be compiled and run, the task is completed. Otherwise, the test cases are improved and completed until they meet the expectations.

[0053] In summary, a unit test case generation system based on a large language model according to an embodiment of the present invention includes: a function dependency analysis engine module, which is used to preprocess a target project, extract function dependency relationships, and generate an abstract syntax tree and a source code file; a large model module, which is used to automatically generate test cases through code context information and optimized prompt words; a verification and optimization module, which is used to verify whether the test cases can be successfully executed by compiling and running the test cases, marking part of the test cases that need further processing, automatically analyzing the cause of the error, optimizing the prompt words, and realizing automatic repair of the part of the test cases. By combining function dependency analysis with a large language model, high-quality test cases can be automatically generated without relying on manual or existing test cases, thereby reducing manual intervention. Furthermore, the functional dependency analysis engine module also includes a source code structure analysis unit, which is used for lexical analysis, grammatical analysis and semantic analysis; the lexical analysis includes: converting the source code into a series of word symbols, deleting comments and redundant spaces, and converting constants from character strings to binary form; the grammatical analysis includes: constructing a syntax tree through recursive descent analysis and predictive analysis, and checking whether it complies with grammatical rules; the semantic analysis includes: performing type checking, symbol parsing, semantic checking and error handling, so as to ensure that the context-related attributes of the program code are correct and generate corresponding error messages; Furthermore, the large model module includes: a prompt word tuning unit, which is used to interact with the function dependency analysis engine module, obtain the source code file, and dynamically adjust and optimize the prompt word according to the source code file; use the generated test cases and their effects for feedback iteration, and adopt chain thinking strategy and analogy prompt strategy to improve the prompt word generation and optimization process; The chain thinking strategy breaks down a big problem into small problems and solves them step by step. By combining text and code, the semantic relationship between text and code can be better understood. The analogy prompt strategy makes inferences by listing relevant cases, which improves the quality of subsequent large model generated content and generates high-quality test cases. Furthermore, the big model module also includes: a big model test case generation unit, which is used to generate test cases using the big model according to the requirements of the prompt words and the source code files; the optimized prompt words and source code files are input into the big model, and the big model has a deep understanding of the input content and logical path; during the generation process, the big model integrates the context information of the code to generate test cases that can fully test each part of the code, thereby being able to efficiently generate comprehensive, high-quality test cases and improve testing efficiency and effectiveness.

[0054] 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 replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A unit test case generation system based on a large language model, characterized in that: include: Function dependency analysis engine module, which is used to preprocess the target project, extract function dependencies, and generate abstract syntax trees and source code files; The large model module is used to automatically generate test cases based on code context information and optimized prompt words; The verification and optimization module is used to verify whether the test case can be successfully executed by compiling and running it, marking some test cases that need further processing, automatically analyzing the cause of the error, optimizing the prompt words, and realizing automatic repair of the part of the test case.

2. The unit test case generation system based on a large language model according to claim 1, characterized in that: The functional dependency analysis engine module includes: The source code preprocessing unit is used to obtain a complete source code list, read the source code directory one by one, and ensure that all functions / classes / project files to be analyzed have been correctly obtained and preprocessed through error checking and generating error logs, providing a basis for subsequent dependency analysis.

3. The unit test case generation system based on a large language model according to claim 1, characterized in that: The functional dependency analysis engine module also includes: Source code structure analysis unit, which is used for lexical analysis, syntax analysis and semantic analysis; The lexical analysis includes: converting the source code into a series of word symbols, removing comments and extra spaces, and converting constants from strings to binary form; The grammatical analysis includes: constructing a grammatical tree through recursive descent analysis and predictive analysis, and checking whether it complies with grammatical rules; The semantic analysis includes: type checking, symbol parsing, semantic checking and error handling.

4. The unit test case generation system based on a large language model according to claim 1, characterized in that: The functional dependency analysis engine module also includes: The dependency extraction and analysis unit is used to find the dependent function set of a function, process the calling relationship between functions, and through a recursive method, gradually analyze all the function sets called by the initial function to build a complete function dependency graph.

5. The unit test case generation system based on a large language model according to claim 1, characterized in that: The functional dependency analysis engine module also includes: The abstract syntax tree generation unit is used to construct an abstract syntax tree, which describes the composition and dependency relationships of various classes, objects, functions, variables and other members in the source code through lexical analysis and syntax analysis.

6. The unit test case generation system based on a large language model according to claim 1, characterized in that: The functional dependency analysis engine module also includes: The data conversion and output unit is used to convert the analysis results into vector data, and generate the source code file for each function and its dependent function set according to the extracted dependency relationship.

7. The unit test case generation system based on a large language model according to claim 1, characterized in that: The large model module includes: A prompt word tuning unit, which is used to interact with the function dependency analysis engine module, obtain the source code file, dynamically adjust and optimize the prompt word according to the source code file; use the generated test cases and their effects for feedback iteration, and adopt chain thinking strategy and analogy prompt strategy to improve the prompt word generation and optimization process; The chain thinking strategy breaks down a big problem into small problems and solves them step by step. By combining text and code together, the semantic relationship between text and code can be better understood. The analogy prompt strategy makes inferences by listing relevant cases, thereby improving the quality of the content generated by the subsequent large model.

8. The unit test case generation system based on a large language model according to claim 1, characterized in that: The large model module also includes: A large model generates test case unit, which is used to generate test cases using the large model according to the requirements of the prompt words and the source code files; The optimized prompt words and source code files are input into the big model, which has a deep understanding of the input content and logical path. During the generation process, the big model integrates the contextual information of the code and generates test cases that can fully test each part of the code.

9. The unit test case generation system based on a large language model according to claim 1, characterized in that: The verification and optimization module includes: The compilation and running verification unit is used to compile and run the generated test cases to verify whether the test cases can be successfully executed. For the compiled test cases, they are directly saved and displayed on the front end to provide support for the user's subsequent unit testing.

10. The unit test case generation system based on a large language model according to claim 1, characterized in that: The verification and optimization module also includes: The automatic repair unit is used to analyze the error causes of test cases that cannot be compiled based on the compilation information, source code information, and prompt word content, further optimize the prompt words based on the error causes, and use the large model to repair the test case again; The completion unit is used to simulate the execution of a program by using abstract symbols instead of specific values, reveal the execution path of the program, and generate corresponding input conditions for a specific program path.

Citation Information

Patent Citations

  • Test case generation method, device and system, offline server and storage medium

    CN113297061A

  • High-reliability unit test automatic generation method and device based on dialogue type large language model

    CN117009231A

  • Unit test method and adjustment method and device of unit test large model

    CN117609015A

  • Automatic test case generation device based on large language model

    CN117806980A

  • Method and device for automatically generating unit test based on thinking chain prompt

    CN118503125A

Cited By

  • Software configuration item test case automatic generation method based on large language model

    CN119336609A

  • Automatic Generation Method of Software Configuration Item Test Cases Based on Large Language Model

    CN119336609B

  • Software testing method and system based on large model

    CN119441065A

  • Dynamic language test case automatic generation method based on large language model

    CN119576799A

  • Test case generation method and device, equipment and medium

    CN119669027A