CN-115576831-A - Test case recommendation method, device, equipment and storage medium
Abstract
The invention discloses a test case recommendation method, a test case recommendation device, test case recommendation equipment and a storage medium. The method comprises the following steps: the method comprises the steps of obtaining a test code, and determining a complete calling relation and a code coverage rate report of the test code; analyzing the code coverage rate report, determining at least one method name to be recommended, and determining abnormal codes corresponding to the method names to be recommended in the test codes; the method name to be recommended is the method name of the uncovered or incompletely covered method in the test code; determining all target application programming interfaces corresponding to the names of the methods to be recommended in the test codes according to the complete calling relationship; and determining at least one case recommendation report according to each target application programming interface, each method name to be recommended and each abnormal code, and determining a target recommended test case according to each case recommendation report. The technical scheme of the embodiment of the invention solves the problem that test cases are easy to miss in manual analysis, and avoids the one-sidedness and instability of manual analysis aiming at code coverage rate report analysis.
Inventors
- YU HONG
Assignees
- AGRICULTURAL BANK CHINA
Dates
- Publication Date
- 20230106
- Application Date
- 20221027
- Priority Date
- 20221027
Claims (10)
- 1. A test case recommendation method is characterized by comprising the following steps: acquiring a test code, and determining a complete calling relationship and a code coverage rate report of the test code; analyzing the code coverage rate report, determining at least one method name to be recommended, and determining abnormal codes corresponding to the method names to be recommended in the test codes; the method name to be recommended is a method name of an uncovered or incompletely covered method in the test code; determining all target application programming interfaces corresponding to the method name to be recommended in the test code according to the complete calling relationship; and determining at least one case recommendation report according to each target application programming interface, each method name to be recommended and each abnormal code, and determining a target recommended test case according to each case recommendation report.
- 2. The method of claim 1, wherein determining the complete invocation relationship and code coverage report for the test code comprises: performing static code analysis on the test code to determine the complete calling relationship of the test code; and when the test code is executed, generating a code coverage report of the test code by a preset code coverage statistical tool.
- 3. The method of claim 1, wherein parsing the code coverage report to determine at least one method name to be recommended comprises: traversing all first type mark files corresponding to the code coverage rate report, and determining node class name information and abnormal line number information; comparing the node class name information with the abnormal line number information with a second type mark file corresponding to the code coverage rate report to determine an abnormal intermediate method name; and removing duplication of each abnormal intermediate method name, and determining at least one method name to be recommended.
- 4. The method of claim 3, wherein traversing all first type markup files corresponding to the code coverage report to determine node class name information and exception line number information comprises: replacing and adjusting preset separators in the path information of each first type markup file, and determining node class name information corresponding to the path information; and traversing lines of each first type of markup file according to a preset abnormal coverage identifier, and determining abnormal line number information.
- 5. The method according to claim 1, wherein the determining, according to the complete call relationship, all target application programming interfaces corresponding to the method name to be recommended in the test code comprises: for each method name to be recommended, determining an upward calling chain corresponding to the method name to be recommended according to the complete calling relationship; and determining the application programming interface carrying preset identification information in the upward calling chain as a target application programming interface corresponding to the name of the method to be recommended.
- 6. The method of claim 1, wherein determining at least one case recommendation report based on each target application programming interface, each method name to be recommended, and each exception code comprises: aiming at each abnormal code, determining a method name to be recommended and a target application programming interface corresponding to the abnormal code; and generating a case recommendation report by using the abnormal code, the method name to be recommended and the target application programming interface according to a first preset report generation format.
- 7. The method of claim 6, wherein if the exception code further includes function interface information, the determining at least one case recommendation report according to each target application programming interface, each method name to be recommended, and each exception code further comprises: determining a method name to be recommended, a target application programming interface and functional interface information corresponding to each abnormal code; and generating a case recommendation report according to the abnormal code, the name of the method to be recommended, the target application programming interface and the functional interface information according to a second preset report generation format.
- 8. A test case recommendation device, comprising: the code information acquisition module is used for acquiring a test code and determining a complete calling relationship and a code coverage rate report of the test code; the exception determining module is used for analyzing the code coverage rate report, determining at least one method name to be recommended, and determining exception codes corresponding to the method names to be recommended in the test codes; the method name to be recommended is a method name of an uncovered or incompletely covered method in the test code; the interface determining module is used for determining all target application programming interfaces corresponding to the names of the methods to be recommended in the test codes according to the complete calling relationship; and the case recommendation module is used for determining at least one case recommendation report according to each target application programming interface, each method name to be recommended and each abnormal code, and determining a target recommendation test case according to each case recommendation report.
- 9. A test case recommendation apparatus, comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein, the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the test case recommendation method of any one of claims 1-7.
- 10. A computer-readable storage medium storing computer instructions for causing a processor to perform the test case recommendation method of any one of claims 1-7 when executed.
Description
Test case recommendation method, device, equipment and storage medium Technical Field The invention relates to the technical field of computer software testing, in particular to a test case recommendation method, device, equipment and storage medium. Background A test case is a set of test inputs, execution conditions, and expected results tailored for a particular purpose in order to test certain program code or verify that certain requirements are met. The black box test method in the traditional mode usually depends on subjective experience of service requirement understanding of testers, test cases are easy to omit, and due to the fact that running codes are invisible, tests which are completely covered aiming at abnormal branches in the codes are difficult to carry out. Therefore, the use of code coverage tool in system function test to monitor the test execution process and count the code coverage result has gradually become an important means widely used in objectively evaluating the validity and sufficiency of the test case set and evaluating the reliability of the test result. However, currently, for the processing of code coverage results, a tester often performs manual analysis on an acquired code coverage report after performing a test, so as to perform test case supplement for codes determined to be uncovered or not covered completely. Although some experiences, methods and knowledge bases for reading code coverage reports are formed at present, some testers with weak code bases often have difficulty in accurately and completely determining test cases needing to be supplemented, so that the test for program codes is insufficient. Disclosure of Invention The invention provides a method, a device, equipment and a storage medium for recommending test cases, which realize automatic analysis of a code coverage rate report and accurate determination of the test cases and improve the accuracy and completeness of test case recommendation. In a first aspect, an embodiment of the present invention provides a test case recommendation method, where the method includes: acquiring a test code, and determining a complete call relation and a code coverage rate report of the test code; analyzing the code coverage rate report, determining at least one method name to be recommended, and determining abnormal codes corresponding to the method names to be recommended in the test codes; the method to be recommended is named as the method name of the uncovered or incompletely covered method in the test code; determining all target application programming interfaces corresponding to the names of the methods to be recommended in the test codes according to the complete calling relation; and determining at least one case recommendation report according to each target application programming interface, each method name to be recommended and each abnormal code, and determining a target recommendation test case according to each case recommendation report. In a second aspect, an embodiment of the present invention further provides a test case recommendation apparatus, where the test case recommendation apparatus includes: the code information acquisition module is used for acquiring the test codes and determining the complete calling relation and the code coverage rate report of the test codes; the anomaly determination module is used for analyzing the code coverage rate report, determining at least one method name to be recommended and determining an anomaly code corresponding to each method name to be recommended in the test codes; the method to be recommended is named as the method name of the uncovered or incompletely covered method in the test code; the interface determining module is used for determining all target application programming interfaces corresponding to the names of the methods to be recommended in the test codes according to the complete calling relationship; and the case recommendation module is used for determining at least one case recommendation report according to each target application programming interface, each method name to be recommended and each abnormal code, and determining a target recommendation test case according to each case recommendation report. In a third aspect, an embodiment of the present invention further provides a test case recommendation device, where the test case recommendation device includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein, the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor such that the at least one processor is capable of implementing the test case recommendation method of any of the embodiments of the present invention. In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where computer instructions are stored, and the computer instructions are con