CN-121996559-A - Test case generation method, device, equipment and computer storage medium
Abstract
The application discloses a test case generation method, a device, equipment and a computer storage medium, wherein the method comprises the steps of carrying out static analysis on a program to be tested to obtain program structure information; the method comprises the steps of executing initial test based on program structure information, collecting initial coverage information, selecting a target path from a path set to be covered based on a dynamic evaluation mechanism and the initial coverage information, carrying out symbolization processing on the target path to generate path constraint and carrying out constraint solving, generating test cases for covering the target path when the constraint solving is successful, generating a guide signal based on an unsuccessful solving part when the constraint solving is unsuccessful, and executing guide search based on the guide signal to generate the test cases for covering the target path. The method and the device can solve the problems that complex branches are difficult to cover due to low random test efficiency, symbol execution path explosion and constraint solving are difficult, a search technology is easy to fall into local optimum and initial exploration efficiency is low, and achieve improvement of test case generation efficiency and path coverage capability.
Inventors
- Request for anonymity
- Tu Hengqiang
- YU LEI
Assignees
- 赛力斯汽车有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260127
Claims (10)
- 1. A method for generating test cases, the method comprising: performing static analysis on a program to be tested to obtain program structure information; Executing an initial test based on the program structure information, and collecting initial coverage information generated by executing the initial test; selecting a target path from a path set to be covered based on a dynamic evaluation mechanism and the initial coverage information; Symbolizing the target path to generate path constraint and solving the constraint; when the constraint solving is successful, generating a test case covering the target path based on a solving result; And when the constraint solving fails, generating a guide signal based on an unsuccessful solving part in the path constraint, and executing guide search based on the guide signal to generate a test case covering the target path.
- 2. The method of claim 1, wherein the step of statically analyzing the program under test to obtain program structure information further comprises: Analyzing the source code of the program to be tested; Constructing a control flow graph of the program to be tested according to the source code; identifying a branch point in the control flow graph and inserting probe codes at the branch point; The program structure information is formed based on the control flow graph and the branch point into which the probe code has been inserted.
- 3. The method of claim 2, wherein the step of performing an initial test based on the program structure information, collecting initial coverage information resulting from performing the initial test, further comprises: generating an initial test input based on the program structure information; Executing the program to be tested, into which the probe code has been inserted, by using the initial test input, and collecting path execution information based on triggering of the probe code; And determining the coverage state of each branch of the program to be tested according to the path execution information to form the initial coverage information.
- 4. The method of claim 2, wherein the step of selecting a target path from a set of paths to be covered based on a dynamic evaluation mechanism and the initial coverage information, further comprises: Determining an uncovered branch in the program to be tested according to the initial coverage information to form the path set to be covered; calculating the selection weight of each path based on at least one characteristic factor of each path in the path set to be covered through the dynamic evaluation mechanism; and selecting one path from the path set to be covered as the target path according to probability distribution of selection weights of the paths.
- 5. The method of claim 4, wherein the steps of symbolizing the target path, generating a path constraint, and solving the constraint further comprise: replacing the input variable of the program to be tested with a symbol variable, and performing simulation execution based on the target path to obtain a symbol execution path; Extracting branch conditions from the symbol execution path, and performing logic combination on the branch conditions to generate the path constraint; and calling a constraint solver to solve the path constraint.
- 6. The method of claim 5, wherein the step of generating test cases covering the target path based on the solution result when the constraint solution is successful, further comprises: Acquiring a specific variable assignment output after the constraint solver successfully solves the path constraint; According to the input interface specification of the program to be tested, assigning the specific variable to form test input data of the program to be tested; and determining the test input data as the test case covering the target path.
- 7. The method of claim 5, wherein the step of generating a pilot signal based on an unsuccessful solution portion of the path constraint when the constraint solution fails, performing a pilot search based on the pilot signal, and generating a test case covering the target path further comprises: identifying constraint conditions which are not successfully solved from the path constraint when the constraint solver fails to solve the path constraint; Generating a guiding signal for guiding the searching direction based on the constraint condition which is not successfully solved; Setting an initial search state and an optimization target of a guided search engine based on the guide signal, and executing the guided search; And when the guided search is successful, generating the test case covering the target path according to the result output by the guided search.
- 8. A test case generating device, the device comprising: The analysis module is used for carrying out static analysis on the program to be tested and obtaining program structure information; the collection module is used for executing initial tests based on the program structure information and collecting initial coverage information generated by executing the initial tests; the selection module is used for selecting a target path from a path set to be covered based on a dynamic evaluation mechanism and the initial coverage information; the processing module is used for carrying out symbolization processing on the target path, generating path constraint and carrying out constraint solving; The first generation module is used for generating a test case covering the target path based on a solving result when the constraint solving is successful; and the second generation module is used for generating a guide signal based on an unsuccessful solving part in the path constraint when the constraint solving fails, executing guide search based on the guide signal and generating a test case covering the target path.
- 9. A test case generating apparatus, comprising: A controller; A memory for storing one or more programs that, when executed by the controller, cause the controller to implement the test case generation method of any one of claims 1 to 7.
- 10. A computer readable storage medium, wherein at least one executable instruction is stored in the storage medium, which when run on a test case generating device/apparatus causes the test case generating device/apparatus to perform the operations of the test case generating method according to any one of claims 1 to 7.
Description
Test case generation method, device, equipment and computer storage medium Technical Field The present application relates to the field of computer software testing technology, and in particular, to a test case generating method, apparatus, device, and computer storage medium. Background At present, automatic test case generation is a key link for guaranteeing software quality and improving development efficiency, and a core challenge is how to efficiently generate test cases which can effectively cover code paths and find deep defects. The prior art mainly covers three types of test case generation modes: 1) The random test is realized by randomly generating test cases, the realization is simple, but the efficiency is low, and the code path with the complex conditional branches is difficult to cover; 2) The technology based on symbol execution converts a program path into constraint conditions and solves the constraint conditions, and has strong path coverage capability but faces problems of path explosion, difficult constraint solving and the like, particularly for nonlinear constraint, floating point number or external function call scenes, the expandability is insufficient in large-scale practical application; 3) The search-based technology treats test generation as optimization problem treatment, but can effectively cope with a target which is difficult to symbolize but is easy to fall into local optimum, and the initial stage exploration efficiency is low. Therefore, it is needed to provide a technical solution to solve the above technical problems. Disclosure of Invention In view of the above problems, the present application provides a test case generating method, apparatus, device, and computer storage medium, which are used for solving the problems in the prior art that random test efficiency is low, complex branches are difficult to cover, symbol execution path explosion and constraint solving are difficult, and a search technology is easy to fall into local optimum and initial exploration efficiency is low. According to an aspect of an embodiment of the present application, there is provided a test case generating method, including: performing static analysis on a program to be tested to obtain program structure information; Executing an initial test based on the program structure information, and collecting initial coverage information generated by executing the initial test; selecting a target path from a path set to be covered based on a dynamic evaluation mechanism and the initial coverage information; Symbolizing the target path to generate path constraint and solving the constraint; when the constraint solving is successful, generating a test case covering the target path based on a solving result; And when the constraint solving fails, generating a guide signal based on an unsuccessful solving part in the path constraint, and executing guide search based on the guide signal to generate a test case covering the target path. In an optional manner, the step of performing static analysis on the program to be tested to obtain program structure information further includes: Analyzing the source code of the program to be tested; Constructing a control flow graph of the program to be tested according to the source code; identifying a branch point in the control flow graph and inserting probe codes at the branch point; The program structure information is formed based on the control flow graph and the branch point into which the probe code has been inserted. In an optional manner, the step of performing an initial test based on the program structure information and collecting initial coverage information generated by performing the initial test further includes: generating an initial test input based on the program structure information; Executing the program to be tested, into which the probe code has been inserted, by using the initial test input, and collecting path execution information based on triggering of the probe code; And determining the coverage state of each branch of the program to be tested according to the path execution information to form the initial coverage information. In an alternative manner, the step of selecting a target path from the set of paths to be covered based on the dynamic evaluation mechanism and the initial coverage information further comprises: Determining an uncovered branch in the program to be tested according to the initial coverage information to form the path set to be covered; calculating the selection weight of each path based on at least one characteristic factor of each path in the path set to be covered through the dynamic evaluation mechanism; and selecting one path from the path set to be covered as the target path according to probability distribution of selection weights of the paths. In an optional manner, the step of performing symbolization processing on the target path, generating a path constraint and performing constraint solving further i