Automatic test case generation method based on large model and particle swarm optimization
Through the method of combining large model and particle swarm algorithm, test cases are generated and optimized, and the problems of low coverage and low efficiency in traditional test case generation methods are solved, and the system boundary conditions and abnormal states are efficiently covered, ensuring the comprehensive system testing is carried out. Sex and reliability.
Patent Information
- Application Number
- CN202411540333.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-01-07
AI Technical Summary
Traditional test case generation methods face the problems of low test coverage, low generation efficiency and inability to cope with complex logic scenarios, and it is difficult to ensure that the generated test cases can effectively cover various boundary situations and abnormal states of the system.
Combining the big model and particle swarm algorithm, the large model extracts semantic information from the requirements document and code comments to generate preliminary test case templates. The particle swarm algorithm performs global search and optimizes input parameter combination and execution paths to ensure that more boundary situations and exceptions are covered. state.
It realizes efficient generation of test cases, covering various functions and boundary situations of the system, and dynamically optimizes test cases through feedback mechanisms to ensure the comprehensiveness and reliability of system tests.
Smart Images

Figure CN119271565A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the fields of electronic engineering and computer science, and in particular relates to an automatic test case generation method based on a large model and a particle swarm algorithm. Background Art
[0002] Software testing is a key link in ensuring the quality and stability of software systems. Traditional test case generation techniques mainly rely on manual writing or automatic generation through random generation algorithms, but these methods usually face problems such as low test coverage, low generation efficiency, and inability to cope with complex logical scenarios. How to improve the efficiency of test case generation and ensure that the generated test cases can effectively cover various boundary conditions and abnormal states of the system is an urgent problem to be solved.
[0003] In recent years, large models have shown strong generation capabilities in the field of natural language processing, and can assist in generating test cases from system documents, code comments and other information. The particle swarm algorithm is a group intelligence algorithm that is good at handling complex optimization problems and has global search capabilities. It can optimize the parameter combination and execution path of test cases. Combining large models with the particle swarm algorithm can effectively improve the quality and efficiency of test case generation and solve the shortcomings of traditional test case generation methods. Summary of the invention
[0004] To solve the above technical problems, the present invention provides an automated test case generation method based on a big model and a particle swarm algorithm. The big model is used to extract semantic information from the requirement documents and code comments of the system under test to generate a preliminary test case template. The particle swarm algorithm is then used to perform a global search in the parameter space to optimize the input parameter combination and execution path of the test case to ensure that more boundary conditions and abnormal states are covered.
[0005] To achieve the above object, the present invention adopts the following technical solutions:
[0006] An automated test case generation method based on a large model and a particle swarm algorithm, comprising:
[0007] Step (1): Design a large language model requirement analysis module to extract semantics from natural language requirement descriptions and code snippets to be tested based on the large model and generate preliminary test case templates:
[0008] Step (2), designing a particle swarm algorithm optimization module, which is used to perform global search and optimization on the input parameter combinations and execution paths in the preliminary test case template based on the particle swarm algorithm, and generate optimized test cases;
[0009] Step (3): Design an automated test execution and feedback module to execute the optimized test cases and provide feedback on the execution results.
[0010] Furthermore, the step (1) includes:
[0011] Step (1.1), the large model is based on the code snippet to be tested and the bimodal data described in natural language. Through cross-modal semantic mapping, the functional logic and test objectives of the system are extracted. Combined with the key terms, special functions, and expert knowledge related to the specific equipment model test, the sequential structure, branch structure, and loop structure in the code are analyzed to generate test points. The test points include trigger conditions, trigger timing, style, functional logic, and exception handling.
[0012] Step (1.2), determine the input conditions, expected output values, and boundary conditions of the system, design test case templates according to different test strategies, the test strategies include positive testing, negative testing, and boundary testing, use the functional logic extracted from the large model and the test objectives to design a mapping from the test point to the test case template, generate a preliminary test case template, the test case template includes the test point, functional flow, test steps, boundary conditions, expected results of potential abnormal situations, etc., pass the generated test case template as input to the particle swarm algorithm optimization module in step 2, and derive the abnormal input conditions in the test case to ensure the diversity and coverage of the test case;
[0013] Furthermore, the step (2) includes:
[0014] Step (2.1), initializing the particle swarm algorithm optimization module, converting the preliminary test case template into the initial position of the particle, and adding multi-objective constraints;
[0015] Step (2.2), evaluate the fitness of each particle according to the fitness function, combine the defect injection test method, simulate the potential defect mode in the code fragment, evaluate the detection effect of each preliminary test case template, estimate the resources and time required for the execution of the preliminary test case template based on time complexity analysis, and regenerate the fitness of each particle;
[0016] Step (2.3), the particle swarm adjusts the search range of particles through adaptive inertia weights during the iteration process. In each iteration, the local optimal and global optimal guidance strategies are used to update the speed and position of each particle. By adjusting the input parameters and execution path, the parameter combination of the preliminary test case template is dynamically optimized, and the fitness of the particles is recalculated. After every several iterations, some particles are chaotically perturbed, and the iteration is continued until the convergence condition is reached, the global optimal particle is found, and the optimized test case is generated.
[0017] Furthermore, the step (3) includes:
[0018] Step (3.1), build a test environment in the system under test and automatically execute optimized test cases, record the execution path, input and output results and system status changes of each optimized test case, monitor the system operation status in real time, and automatically capture abnormal status;
[0019] Step (3.2): Re-evaluate the fitness value of the particle according to the results of the optimized test case execution, use the dynamic adjustment mechanism of defect coverage, dynamically update the fitness value according to the number and type of defects found, and continue to iterate and optimize the particle swarm based on the feedback results to ensure that the quality and coverage of the test cases can be gradually improved in each iteration;
[0020] Step (3.3): When the system version is updated or the complexity changes, the optimized test case generation parameters are automatically adjusted to ensure that the generated optimized test cases always adapt to the complexity and demand changes of the current system.
[0021] The beneficial effects of the present invention are:
[0022] The present invention can effectively generate efficient test cases, cover various functions and boundary conditions of the system, and realize dynamic optimization of test cases through a feedback mechanism, thereby ensuring the comprehensiveness and reliability of system testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a flow chart of an automated test case generation method based on a large model and a particle swarm algorithm according to the present invention. DETAILED DESCRIPTION
[0024] The present invention is further described in detail below with reference to the accompanying drawings.
[0025] The present invention relates to an automated test case generation method based on a large model and a particle swarm algorithm, comprising the design of a large model requirement analysis module, a particle swarm algorithm optimization module, and an automated test execution and feedback module. The method can achieve efficient and intelligent test case generation and optimization to a certain extent, and improve test coverage and defect detection capabilities through a feedback mechanism, thereby ensuring comprehensive testing of system functions and performance.
[0026] The structural block diagram of the present invention is as follows Figure 1 As shown, the specific implementation is as follows:
[0027] (1) Design a large model requirement analysis module, which is used to generate preliminary test case templates. The specific implementation is as follows:
[0028] ① Use the pre-trained big model for fine-tuning, input the system's requirement documents, code comments, historical test cases and other data, and the big model generates preliminary test case templates that meet the specific requirements of the system through semantic understanding. In this process, the big model uses cross-modal semantic mapping technology to extract the system's functional logic from the code and documents, generate test points, and then generate test case templates in combination with the test objectives, and extract key test paths through automated analysis.
[0029] ② The fine-tuned large model can identify the functional logic and business requirements in the system, and the generated test cases include input parameters, test paths and boundary conditions to ensure that key functional modules and special scenarios are covered. Using boundary condition analysis technology, the system can identify potential defects, such as boundary values in loops, unhandled exception paths, etc. The large model can further analyze the type of input parameters, boundary conditions and exception patterns, and the generated test cases cover normal operations and potential defect scenarios.
[0030] (2) Design a particle swarm algorithm optimization module, which is used to globally optimize the initially generated test case templates to improve test coverage and defect detection capabilities. The specific implementation is as follows:
[0031] ① Generate the parameter combination of the initial test case and convert the test template generated by the large model into the initial position of the particle. At the same time, set constraints, such as minimizing redundant test data and giving priority to covering critical paths.
[0032] ② Evaluate the fitness of each particle based on the fitness function, combine the defect injection test method, simulate the potential defect mode in the code snippet, evaluate the detection effect of each preliminary test case template, and estimate the resources and time required for the execution of the preliminary test case template based on time complexity analysis, and regenerate the fitness of each particle. The particle swarm algorithm evaluates the performance of each particle based on the fitness function, which includes indicators such as test coverage, defect detection capability, and execution efficiency.
[0033] ③ During the iteration process, the particle swarm adjusts the search range of particles through adaptive inertia weights. In each iteration, the local optimal and global optimal guidance strategies are used to update the speed and position of each particle. By adjusting the input parameters and execution path, the parameter combination of the preliminary test case template is dynamically optimized, and the fitness of the particles is recalculated. After every several iterations, some particles are chaotically perturbed, and the iteration is continuously performed until the convergence conditions are reached, the global optimal particles are found, and optimized test cases are generated to ensure that the generated test cases cover more boundary conditions and extreme scenarios.
[0034] (3) Design an automated test execution and feedback module, which is implemented as follows:
[0035] ① Use the generated and optimized test case set to perform automated testing on the system under test. During the test execution, the system's operating status will be monitored in real time. This process includes detecting abnormal conditions such as memory leaks, deadlocks, performance bottlenecks, and recording the execution results of each test case.
[0036] ② According to the test execution results, re-evaluate the fitness value of the particles and dynamically update the fitness value of the particles, especially the adjustment of the defect coverage. Dynamically update the fitness value according to the number and type of defects found, and continue to iterate and optimize the particle swarm in combination with the feedback results. This module can combine defect injection testing technology to simulate potential defects in the real system, thereby further improving the detection capability of test cases.
[0037] ③ When the system version is updated or the complexity changes, the test case generation parameters are automatically adjusted to ensure that the generated test cases always adapt to the complexity and demand changes of the current system.
[0038] In summary, the present invention discloses an automated test case generation method based on a large model and a particle swarm algorithm, including the design of a large model fine-tuning module, a particle swarm algorithm optimization module, and an automated test execution and feedback module. It can effectively generate efficient test cases, cover various functions and boundary conditions of the system, and realize dynamic optimization of test cases through a feedback mechanism, thereby ensuring the comprehensiveness and reliability of system testing.
[0039] The contents not described in detail in the specification of the present invention belong to the prior art known to the professional and technical personnel in this field.
[0040] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for generating automated test cases based on a large model and a particle swarm algorithm, characterized in that: include: Step (1): Design a large language model requirement analysis module to extract semantics from natural language requirement descriptions and code snippets to be tested based on the large model and generate preliminary test case templates: Step (2), designing a particle swarm algorithm optimization module, which is used to perform global search and optimization on the input parameter combinations and execution paths in the preliminary test case template based on the particle swarm algorithm, and generate optimized test cases; Step (3): Design an automated test execution and feedback module to execute the optimized test cases and provide feedback on the execution results.
2. The method for generating automated test cases based on a large model and a particle swarm algorithm according to claim 1, characterized in that: The step (1) comprises: Step (1.1), the large model is based on the code snippet to be tested and the natural language description bimodal data, and through cross-modal semantic mapping, it extracts the functional logic and test objectives of the system and generates test points; Step (1.2): determine the input conditions, expected output values, and boundary conditions of the system, and design test case templates according to different test strategies, including positive testing, negative testing, and boundary testing. Use the functional logic and test objectives extracted from the large model to design a mapping from test points to test case templates, and generate a preliminary test case template.
3. The method for generating automated test cases based on a large model and a particle swarm algorithm according to claim 1, characterized in that: The step (2) comprises: Step (2.1), initializing the particle swarm algorithm optimization module, converting the preliminary test case template into the initial position of the particle, and adding multi-objective constraints; Step (2.2), evaluate the fitness of each particle according to the fitness function, combine the defect injection test method, simulate the potential defect mode in the code fragment, evaluate the detection effect of each preliminary test case template, estimate the resources and time required for the execution of the preliminary test case template based on time complexity analysis, and regenerate the fitness of each particle; Step (2.3), the particle swarm adjusts the search range of particles through adaptive inertia weights during the iteration process. In each iteration, the local optimal and global optimal guidance strategies are used to update the speed and position of each particle. By adjusting the input parameters and execution path, the parameter combination of the preliminary test case template is dynamically optimized, and the fitness of the particles is recalculated. After every several iterations, some particles are chaotically perturbed, and the iteration is continued until the convergence condition is reached, the global optimal particle is found, and the optimized test case is generated.
4. The method for generating automated test cases based on a large model and a particle swarm algorithm according to claim 1, characterized in that: The step (3) comprises: Step (3.1), build a test environment in the system under test and automatically execute optimized test cases, record the execution path, input and output results and system status changes of each optimized test case, monitor the system operation status in real time, and automatically capture abnormal status; Step (3.2), based on the results of the optimized test case execution, re-evaluate the fitness value of the particle, use the dynamic adjustment mechanism of defect coverage, dynamically update the fitness value according to the number and type of defects found, and continue to iterate the optimization of the particle swarm based on the feedback results; Step (3.3): When the system version is updated or the complexity changes, the optimized test case generation parameters are automatically adjusted to ensure that the generated optimized test cases always adapt to the complexity and demand changes of the current system.
Citation Information
Cited By
Dynamic language test case automatic generation method based on large language model
CN119576799A
Software configuration item test case data processing analysis method based on large language model
CN119883940A
Fuzzy test method and device for automatically generating business test case by large model
CN120066961A
Efficient PL / SQL database test case generation method and system
CN120407424A
A high-efficiency PL / SQL database test case generation method and system
CN120407424B