A method and product for generating evaluation results of test cases

By obtaining the target path set of target programs and determining the importance of nodes, combining the execution path and target path of test cases, the evaluation function is designed to calculate the evaluation results of test cases, and the problem of insufficient branch distance and layer proximity in the existing technology is solved, and more accurate test case evaluation is achieved.

CN119759762APending Publication Date: 2025-04-04CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411782320.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

When evaluating the advantages and disadvantages of test cases, the branch distance and layer proximity have limitations, and it is impossible to effectively distinguish the differences or advantages and disadvantages of different test cases.

Method used

By obtaining the target path set of target programs, the importance of each node is determined, and based on the node importance, the execution path of the target test case and the evaluation function of the target path design, the evaluation results of the test case are calculated.

Benefits of technology

This method can generate more accurate test case evaluation results, making up for the problem that branch distance and layer proximity are not enough to distinguish the advantages and disadvantages of test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759762A_ABST
    Figure CN119759762A_ABST
Patent Text Reader

Abstract

The present application provides a method and product for generating evaluation results of test cases, belonging to the technical field of testing. The method comprises obtaining a target path set of a target program; running the target program based on a target test case corresponding to any target path of the target program to obtain the execution path of the target test case; obtaining the evaluation result of the target test case through an evaluation function calculation according to the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents a line of code in the target program, and the importance represents the degree of contribution of any node to the target path set. The present application aims to generate more accurate evaluation results for test cases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of testing, and in particular, to a method and product for generating evaluation results of a test case. Background Art

[0002] With the development of science and technology, computer software has become inseparable from people's lives. Through the iteration of software versions, the code structure has become more complex with the increase of functions. Therefore, software testing technology is needed to ensure the quality of software. Designing reasonable test cases is the prerequisite for ensuring software quality. Further, how to evaluate the quality of test cases is the key point. Constructing a problem model that can evaluate the quality of test cases plays a key role in ensuring software quality.

[0003] The current method is to convert the test case evaluation problem into a combinatorial optimization problem, and then build a problem model. The quality of the test case is measured by constructing a branch distance function and a layer proximity function or integrating these two functions; branch distance is to evaluate the quality of the test case by analyzing the deviation degree of each branch on the execution path of the test case and the target path. Different test cases may execute different paths, but their branch distances are the same. Therefore, there are limitations in using branch distance to judge the quality of the test case; layer proximity is to measure the quality of the test case by calculating the proximity between the execution path of the test case and the target path. The layer proximity is generally the ratio of the number of nodes in the target path included in the execution path of the test case to the target path. However, different test cases execute different paths but have the same layer proximity, and it is impossible to distinguish the differences or quality between the test cases. Summary of the invention

[0004] The embodiments of the present application provide a method and product for generating evaluation results of a test case, aiming to generate more accurate evaluation results of the test case.

[0005] In a first aspect, an embodiment of the present application provides a method for generating evaluation results of a test case, the method comprising: Get the target path set of the target program; Running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case; According to the importance of each node in the target path set, any target path and the execution path of the target test case, the evaluation result of the target test case is obtained by calculating the evaluation function; wherein any node represents the code line in the target program, and the importance represents the contribution degree of any node to the target path set.

[0006] Optionally, obtain a target path set of the target program, including: Obtain any target path of the target program; Generate a multi-branch tree graph corresponding to the target program according to all target paths of the target program, wherein the number of leaf nodes in the multi-branch tree graph is the same as the number of target paths of the target program; The path set from the root node to all leaf nodes of the multi-branch tree graph is used as the target path set.

[0007] Optionally, after obtaining the target path set of the target program, the method further includes: For any node in the multi-branch tree graph, the importance corresponding to the node is determined according to the proportion of the number of target paths where the node is located in the target path set.

[0008] Optionally, after obtaining the target path set of the target program, the method further includes: Initialize a one-dimensional array corresponding to any target path of the target program, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; According to the multi-branch tree graph, a one-dimensional array corresponding to any target path is assigned a value to obtain a target array corresponding to the target path.

[0009] Optionally, running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case includes: Inserting a stub function at the target location of the target program; The target program is run based on the target test case, and an execution path of the target test case is determined through the stub function.

[0010] Optionally, running the target program based on the target test case and determining the execution path of the target test case through the stub function includes: Initialize a one-dimensional array corresponding to the execution path of the target test case, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; The target program is run based on the target test case, and each node executed by the target test case during the running process is determined through the stub function, and a one-dimensional array corresponding to the execution path of the target test case is assigned to obtain an execution array corresponding to the execution path of the target test case.

[0011] Optionally, obtaining an evaluation result of the target test case by calculating an evaluation function according to the importance of each node in the target path set, any target path and the execution path of the target test case includes: According to the importance of each node, the target array corresponding to any target path and the execution array corresponding to the execution path of the target test case, the evaluation result of the target test case is calculated by the evaluation function; The calculation formula of the evaluation function is:

[0012] Wherein, F(a) is the evaluation result of the target test case a; D(a) is the sum of the branch distances of the target test case a; is the importance of node Ri; is the value of the node Ri in the execution array; is the value of the node Ri in the target array; i is the node index; n is the total number of nodes.

[0013] In a second aspect, an embodiment of the present application provides a device for generating evaluation results of a test case, the device comprising: A first acquisition module is used to acquire a target path set of a target program; A second acquisition module is used to run the target program based on a target test case corresponding to any target path of the target program to acquire an execution path of the target test case; An evaluation result generation module is used to obtain the evaluation result of the target test case through evaluation function calculation according to the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents the code line in the target program, and the importance represents the contribution of any node to the target path set.

[0014] In a third aspect, an embodiment of the present application provides a computer device, comprising: at least one processor, and a memory, wherein the memory stores a computer program that can be run on the processor, wherein when the processor executes the computer program, the method for generating evaluation results of the test case described in the first aspect of the embodiment is executed.

[0015] In a fourth aspect, an embodiment of the present application provides a non-volatile readable storage medium, wherein the non-volatile readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the method for generating evaluation results of the test case described in the first aspect of the embodiment is executed.

[0016] Beneficial effects: Obtain a target path set of a target program; run the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case; obtain an evaluation result of the target test case by calculating an evaluation function according to the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents a line of code in the target program, and the importance represents the degree of contribution of any node to the target path set.

[0017] This method determines the importance of each node according to the contribution of each node in the target path set of the target program to the target path set. After obtaining the execution path of the target test case, the evaluation function designed based on the node importance, the execution path of the target test case and the target path can make up for the problem that branch distance and layer proximity are not sufficient to distinguish the quality of test cases, and can generate more accurate evaluation results for test cases. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0019] Figure 1 It is a flowchart of the steps of the method for generating evaluation results of a test case proposed in an embodiment of the present application; Figure 2 is a schematic diagram of a multi-branch tree diagram proposed in an embodiment of the present application; Figure 3 It is a functional module diagram of a test case evaluation result generating device provided by an embodiment of the present application; Figure 4 is a schematic diagram of a computer device proposed in one embodiment of the present application; Figure 5 It is a schematic diagram of a non-volatile readable storage medium proposed in an embodiment of the present application. DETAILED DESCRIPTION

[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0021] With the development of science and technology, computer software has become inseparable from people's lives. Through the iteration of software versions, the code structure has become more complex with the increase of functions. Therefore, software testing technology is needed to ensure the quality of the software. Therefore, designing reasonable test cases is the prerequisite for ensuring software quality. Further, how to evaluate the pros and cons of test cases is the key point. Constructing a problem model that can evaluate the pros and cons of test cases plays a key role in ensuring software quality.

[0022] Currently, evaluating test cases based on condition coverage, statement coverage, path coverage, and judgment coverage has been widely studied, but each method has certain defects and cannot guarantee the integrity of the test cases, and thus cannot guarantee the quality of the software.

[0023] Another approach is to convert the test case evaluation problem into a combinatorial optimization problem, and then build a problem model to measure the quality of the test cases by constructing a branch distance function and a layer proximity function or integrating these two functions.

[0024] Branch distance evaluates the quality of a test case by analyzing the degree of deviation between the execution path of the test case and each branch on the target path. Different test cases may execute different paths, but their branch distances are the same. Therefore, there are limitations in using branch distance to judge the quality of a test case.

[0025] Layer proximity measures the quality of a test case by calculating the degree of proximity between the test case's execution path and the target path. Layer proximity is generally the ratio of the number of nodes in the target path included in the test case's execution path to the target path. However, different test cases may execute different paths but have the same layer proximity, making it impossible to distinguish the differences or quality of the test cases.

[0026] Therefore, in order to generate more accurate evaluation results for test cases, an embodiment of the present application provides a method for generating evaluation results for test cases.

[0027] Reference Figure 1 , shows a flowchart of a method for generating an evaluation result of a test case in an embodiment of the present application, the method may include the following steps: S101: Obtain a target path set of a target program.

[0028] Specifically, the target program is a designed program. There are different target paths in the target program. For example, after if conditional judgment or loop condition, the target program will have many different execution branches. According to the design of the target program, all target paths corresponding to the target program can be determined, and all target paths constitute a target path set.

[0029] In a feasible implementation, a multi-branch tree diagram may be used to intuitively reflect the target path set of the target program. Specifically, the process of obtaining the target path set of the target program includes the following steps: A1: Obtain any target path of the target program.

[0030] In the actual implementation process, program static analysis can be used to analyze the target program. Program static analysis generates a directed control flow graph without running the target program code. Any target path of the target program can be determined based on the control flow graph; or all target paths determined according to the design of the target program can be manually uploaded.

[0031] A2: Generate a multi-branch tree graph corresponding to the target program according to all target paths of the target program.

[0032] The number of leaf nodes in the multi-branch tree graph is the same as the number of target paths of the target program; in the actual implementation process, any node represents a code line in the target program.

[0033] For example, any code line in the target program may correspond to a node. For example, if there are 10 lines of code in the target program, there are 10 corresponding nodes.

[0034] A node can also be mapped to a code segment. The lines of code in the code segment are executed in sequence, and there are no code lines that cause the path to fork due to if conditional judgments or loop conditions. For example, there are 10 lines of code in the target program, lines 1-3 are executed in sequence, and the 4th line is a code line for if conditional judgment. When the if condition is met, lines 5-7 are executed, and when the if condition is not met, lines 8-10 are executed. Then, 1 node can be mapped to lines 1-3, 1 node to line 4, 1 node to line 5-7, and 1 node to line 8-10.

[0035] The selection may be made based on the size adaptability of the code in actual applications, and this embodiment does not impose any limitation thereto.

[0036] A3: The path set from the root node to all leaf nodes of the multi-branch tree graph is used as the target path set.

[0037] According to the nodes contained in the path of the target program, a multi-branch tree graph corresponding to the target program can be generated, and the number of leaf nodes in the multi-branch tree graph is the set of all target paths of the target program; the multi-branch tree graph can intuitively reflect all target paths of the target program and each node on any target path.

[0038] Furthermore, after obtaining the target path set of the target program, for any node in the multi-branch tree graph, the importance corresponding to the node is determined according to the proportion of the number of target paths where the node is located in the target path set.

[0039] Specifically, the calculation formula of importance is:

[0040] Among them, Ri is the i-th node in the multi-branch tree graph.

[0041] Based on the number of target paths containing the Ri node and the total number of target paths of the target program, the contribution of the Ri node to the target path set of the target program can be determined. The more target paths the Ri node is located in, the greater the contribution of the Ri node and the greater the importance value.

[0042] For example, assuming that the target program has 10 target paths, 4 of which include the Ri node, the importance of the Ri node is 4 / 10=0.4.

[0043] Furthermore, in order to simplify the description of the path, a binary encoding method can be used to represent any path.

[0044] Specifically, after obtaining the target path set of the target program, first, a one-dimensional array corresponding to any target path of the target program is initialized, and the number of elements in the array is the same as the number of nodes in the multi-branch tree graph.

[0045] Then, according to the multi-branch tree graph, a one-dimensional array corresponding to any target path is assigned a value to obtain a target array corresponding to the target path.

[0046] For example, if the number of nodes in the multi-branch tree graph of the target program is 10, the determined one-dimensional array contains 10 elements, and all elements in the initialized one-dimensional array are 0; assuming that a target path of the target program includes R0, R2, R5 and R8 in the execution order, the target array corresponding to the target path is [1,0,1,0,0,1,0,0,1,0].

[0047] S102: Running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case.

[0048] In order to test the quality of a target test case of any target path in a target program, the target program is run with the target test case to obtain the actual execution path of the target test case, and then the quality of the target test case can be determined based on the execution path of the target test case.

[0049] In the actual implementation process, in the process of obtaining the execution path of the target test case, a stub function is inserted at the target position of the target program.

[0050] For example, the target position can be set according to the needs of actual application. When the code lines of the target program are less, the target position can be set for each code line, so that the detailed execution path of the target test case can be tracked; in order to reduce the running cost, you can choose to insert a stub function at the key position of each bifurcation path, but the distribution of the stub function needs to ensure that all target paths of the target program can be covered.

[0051] Then, the target program is run based on the target test case, and the execution path of the target test case is determined through the stub function.

[0052] In the actual implementation process, in order to simplify the description of the execution path of the target test case, binary encoding is also used to represent the execution path, and a one-dimensional array corresponding to the execution path of the target test case is initialized. The number of elements in the array is the same as the number of nodes in the multi-branch tree diagram.

[0053] The target program is run based on the target test case, and each node executed by the target test case during the running process is determined through the stub function, and a one-dimensional array corresponding to the execution path of the target test case is assigned to obtain an execution array corresponding to the execution path of the target test case.

[0054] S103: obtaining an evaluation result of the target test case through calculation using an evaluation function according to the importance of each node in the target path set, any target path and the execution path of the target test case.

[0055] Taking into account that different paths may have the same branch distance and that different paths may have the same layer proximity index, when determining the evaluation result of the target test case in this embodiment, the evaluation function is calculated based on the importance of each node, which can make up for the problem that the branch distance and layer proximity are not sufficient to distinguish the quality of the test case.

[0056] In a feasible implementation, after obtaining the execution path of the target test case, the evaluation result of the target test case can be calculated by the evaluation function according to the importance of each node, the target array corresponding to any target path and the execution array corresponding to the execution path of the target test case.

[0057] The calculation formula of the evaluation function is:

[0058] Wherein, F(a) is the evaluation result of the target test case a; D(a) is the sum of the branch distances of the target test case a; is the importance of node Ri; is the value of the node Ri in the execution array; is the value of the node Ri in the target array; i is the node index; n is the total number of nodes.

[0059] In this embodiment, when determining the branch distance of the target test case a, the branch distance function is extended with logical "AND" and logical "OR" operations. Specifically, the branch distance function for logical "AND" and logical "OR" operations is shown in Table 1 below.

[0060] Table 1 Logical “AND” and logical “OR” operations of branch distance functions

[0061] Wherein, K is a constant, such as K can be 1.

[0062] Because there may be multiple branches in the code, Bi is used to represent the i-th branch in the code.

[0063] Suppose the Bi branch statement is x>2&&y<1, and the test case is a(x,y)=(5,4), then P and Q in the statement correspond to the judgment statement x>2 and y<1. Substitute the test case a into the branch distance function, the first expression is true, and the second expression is false, so D(Bi) should take the maximum value of D(P) and D(Q) + K (such as K=1); because x=5 is greater than 2, x=4 satisfies P, so D(P)=0, and y=4 does not satisfy y<1, so the value of D(Q) is the absolute value of |4-1|, which is 3, then D(Bi)=D(Q)+1=4.

[0064] Suppose the Bi branch statement is x>2||y<1, test case a(x,y)=(5,4), then P and Q in the statement correspond to the judgment statement x>2 and y<1; substitute test case a into the branch distance function, the first expression is true, as long as one of the conditions in the logical AND is true, the branch distance function is true, that is, D(Bi)=0; suppose test case b(x,y)=(1,3), substitute test case b into the branch distance function, at this time P and Q are both false, so D(Bi) should take the minimum value of D(P) and D(Q) and then + K, D(P)=|1-2|=1, D(Q)=|3-1|=2, so D(Bi)=D(P)+1=2.

[0065] After obtaining the target path set of the target program, the method runs the target program based on the target test case corresponding to any target path of the target program to obtain the execution path of the target test case; then, according to the importance of each node in the target path set, any target path and the execution path of the target test case, the evaluation result of the target test case is calculated through an evaluation function, and the importance of each node is determined according to the contribution of each node in the target path set of the target program to the target path set. After obtaining the execution path of the target test case, the evaluation function designed based on the node importance, the execution path of the target test case and the target path can make up for the problem that branch distance and layer proximity are not sufficient to distinguish the quality of test cases, and can generate more accurate evaluation results for test cases.

[0066] In a feasible implementation manner, the execution process of the method is introduced by taking target program A as an example.

[0067] The target program A is a program code for determining the shape of a triangle, wherein the input parameters x, y, and z of the target program are the lengths of the three sides of the triangle. , the code of target program A is as follows: if (x+y>z&&x+z>y&&y+z>x) if (x==y || x==z || y==z) if (y==z&&y==x) print("The triangle is an equilateral triangle") else: print("The triangle is an isosceles triangle") else: print("The triangle is a normal triangle") else: print("Not a triangle") The target program A has 10 lines of code. In this implementation, each line of code corresponds to a node, and the nodes include R0, R1, R2, R3, R4, R5, R6, R7, R8, and R9.

[0068] Static analysis is performed on the code of target program A to determine that there are four target paths and obtain a multi-branch tree graph of target program A.

[0069] Reference Figure 2 , shows a schematic diagram of a multi-branch tree diagram provided in an embodiment of the present application, wherein the multi-branch tree diagram of the target program A includes four target paths, namely: The first target path: R0, R1, R2, R3; The second target path: R0, R1, R2, R4, R5; The third target path: R0, R1, R6, R7; Fourth target path: R0, R8, R9.

[0070] And determine the target arrays corresponding to the four target paths respectively: The target array of the first target path is: [1,1,1,1,0,0,0,0,0,0]; The target array of the second target path is: [1,1,1,0,1,1,0,0,0,0]; The target array of the third target path is: [1,1,0,0,0,0,1,1,0,0]; The target array for the fourth target path is: [1,0,0,0,0,0,0,0,1,1].

[0071] Next, according to the calculation formula of the importance of any node:

[0072] The importance of any node in the target program A is calculated respectively. The importance of each node is shown in Table 2 below.

[0073] Table 2 The importance of each node

[0074] For example, if R0 is in 4 target paths, the importance of R0 is 4 / 4=1; if R4 is in 1 target path, the importance of R4 is 1 / 4=0.25.

[0075] This implementation takes the second target path as an example and generates evaluation results of the corresponding five target test cases.

[0076] According to the code of target program A, the expression of the target test case is the input variables of the three sides of the triangle, that is, solu=[x,y,z].

[0077] The input variable values ​​of the 5 target test cases are divided into: Target test case a: x=4, y=2, z=1; Target test case b: x=7, y=6, z=5; Target test case c: x=3, y=5, z=7; Target test case d: x=4, y=4, z=6; Target test case e: x=3, y=3, z=3.

[0078] Based on the five target test cases, the target program A is run respectively. According to the importance of each node, the execution array corresponding to any target test case and the target array of the second target path, the evaluation function is used to calculate and obtain the evaluation result of each target test case.

[0079] The evaluation results of each target test case are shown in Table 3 below.

[0080] Table 3 Evaluation results of each target test case

[0081] Table 3 also includes the evaluation results of each target test case based on the current layer proximity only and the branch distance and calculation only. The layer proximity represents the ratio of the number of overlapping nodes in the execution array and the target array. For example, taking the target test case a as an example, the nodes with the same values ​​in the execution array and the target array include R0, R3, R6, and R7, and the layer proximity of the target test case a is 4 / 10.

[0082] Based on Table 3, we can see that: (1) The execution array of the target test case d is the same as the target array, that is, the execution path of the target test case d is the target path. At this time, the evaluation result obtained based on the evaluation function in this method is 0.

[0083] (2) Target test cases b and c have the same path. At this time, the layer proximity of the target test cases is the same. Therefore, the advantages and disadvantages of target test cases b and c cannot be evaluated by layer proximity alone. However, target test cases b and c actually have different branch distances. Therefore, the evaluation results of target test cases b and c can be calculated through the evaluation function in this method. According to the evaluation results, for the second target path, target test case b is better than target test case c, so the advantages and disadvantages of target test cases b and c can be distinguished.

[0084] (3) Target test cases d and e have different paths but the same branch distances and . Therefore, the advantages and disadvantages of target test cases d and e cannot be evaluated based on the branch distances and . However, according to the evaluation results of target test cases d and e calculated by the evaluation function in this method, for the second target path, target test case d is better than target test case e.

[0085] The smaller the value of the evaluation result calculated by the evaluation function in this method, the better the target test case is for the target path; only based on layer proximity and only based on branch distance, it is impossible to distinguish the pros and cons of some test cases, and the evaluation function according to this method can generate more accurate evaluation results to distinguish the pros and cons of different test cases. For example, for the second target path, the ranking of the pros and cons of the 5 target test cases is: debca.

[0086] This method solves the problem that branch distance and layer proximity cannot distinguish the quality of test cases in some cases, thereby generating more accurate evaluation results for test cases. The evaluation function can also be used in the algorithm for automatically generating test cases as a judgment condition for selecting solutions and retaining solutions, thereby retaining high-quality solutions, effectively providing high-quality test cases for software testing, and thus providing assurance for software quality.

[0087] Reference Figure 3 , shows a functional module diagram of a test case evaluation result generating device provided in an embodiment of the present application, the device comprising: A first acquisition module 100 is used to acquire a target path set of a target program; A second acquisition module 200 is used to run the target program based on a target test case corresponding to any target path of the target program to acquire an execution path of the target test case; The evaluation result generation module 300 is used to obtain the evaluation result of the target test case through evaluation function calculation according to the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents the code line in the target program, and the importance represents the contribution of any node to the target path set.

[0088] Optionally, the first acquisition module includes a multi-branch tree graph acquisition unit, which is used to: Obtain any target path of the target program; Generate a multi-branch tree graph corresponding to the target program according to all target paths of the target program, wherein the number of leaf nodes in the multi-branch tree graph is the same as the number of target paths of the target program; The path set from the root node to all leaf nodes of the multi-branch tree graph is used as the target path set.

[0089] Optionally, the device further comprises: The importance determination module is used to determine the importance corresponding to any node in the multi-branch tree diagram according to the proportion of the number of target paths where the node is located in the target path set.

[0090] Optionally, the device further comprises: A target array determination module, used for initializing a one-dimensional array corresponding to any target path of the target program, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; According to the multi-branch tree graph, a one-dimensional array corresponding to any target path is assigned a value to obtain a target array corresponding to the target path.

[0091] Optionally, the second acquisition module includes an execution path acquisition unit, configured to: Inserting a stub function at the target location of the target program; The target program is run based on the target test case, and an execution path of the target test case is determined through the stub function.

[0092] Optionally, the second acquisition module includes an execution array determination unit, configured to: Initialize a one-dimensional array corresponding to the execution path of the target test case, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; The target program is run based on the target test case, and each node executed by the target test case during the running process is determined through the stub function, and a one-dimensional array corresponding to the execution path of the target test case is assigned to obtain an execution array corresponding to the execution path of the target test case.

[0093] Optionally, the evaluation result generation module includes an evaluation result generation unit, which is used to: According to the importance of each node, the target array corresponding to any target path and the execution array corresponding to the execution path of the target test case, the evaluation result of the target test case is calculated by the evaluation function; The calculation formula of the evaluation function is:

[0094] Wherein, F(a) is the evaluation result of the target test case a; D(a) is the sum of the branch distances of the target test case a; is the importance of node Ri; is the value of the node Ri in the execution array; is the value of the node Ri in the target array; i is the node index; n is the total number of nodes.

[0095] Reference Figure 4 , shows a schematic diagram of a computer device provided in an embodiment of the present application, including: at least one processor 401, and a memory 402, wherein the memory 402 stores a computer program that can be run on the processor 401, wherein the processor 401 executes the method for generating evaluation results of the test case described in the embodiment when executing the computer program.

[0096] The processor 401 executes the method for generating evaluation results of the test case described in the embodiment when executing the computer program, specifically including the following steps: obtaining a target path set of a target program; running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case; obtaining an evaluation result of the target test case by calculating an evaluation function based on the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents a line of code in the target program, and the importance represents the degree of contribution of any node to the target path set.

[0097] Reference Figure 5 , showing a schematic diagram of a non-volatile readable storage medium provided in an embodiment of the present application, wherein the non-volatile readable storage medium 500 stores a computer program 501, wherein when the computer program 501 is executed by a processor, the method for generating evaluation results of the test case described in the embodiment is executed.

[0098] The computer program 501, when executed by the processor, executes the method for generating evaluation results of the test case described in the embodiment, specifically including the following steps: obtaining a target path set of a target program; running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case; obtaining an evaluation result of the target test case by calculating an evaluation function based on the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents a line of code in the target program, and the importance represents the degree of contribution of any node to the target path set.

[0099] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0100] It should be understood by those skilled in the art that the embodiments of the present application can be provided as methods, devices or computer program products. Therefore, the embodiments of the present application can be in the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the embodiments of the present application can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0101] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0102] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0103] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0104] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0105] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0106] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for generating evaluation results of a test case, characterized in that: The method comprises: Get the target path set of the target program; Running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case; According to the importance of each node in the target path set, any target path and the execution path of the target test case, the evaluation result of the target test case is obtained by calculating the evaluation function; wherein any node represents the code line in the target program, and the importance represents the contribution degree of any node to the target path set.

2. The method according to claim 1, characterized in that: Get the target path set of the target program, including: Obtain any target path of the target program; Generate a multi-branch tree graph corresponding to the target program according to all target paths of the target program, wherein the number of leaf nodes in the multi-branch tree graph is the same as the number of target paths of the target program; The path set from the root node to all leaf nodes of the multi-branch tree graph is used as the target path set.

3. The method according to claim 2, characterized in that After obtaining the target path set of the target program, the method further includes: For any node in the multi-branch tree graph, the importance corresponding to the node is determined according to the proportion of the number of target paths where the node is located in the target path set.

4. The method according to claim 3, characterized in that After obtaining the target path set of the target program, the method further includes: Initialize a one-dimensional array corresponding to any target path of the target program, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; According to the multi-branch tree graph, a one-dimensional array corresponding to any target path is assigned a value to obtain a target array corresponding to the target path.

5. The method according to claim 4, characterized in that Running the target program based on a target test case corresponding to any target path of the target program to obtain an execution path of the target test case includes: Inserting a stub function at the target location of the target program; The target program is run based on the target test case, and an execution path of the target test case is determined through the stub function.

6. The method according to claim 5, characterized in that Running the target program based on the target test case and determining the execution path of the target test case through the stub function includes: Initialize a one-dimensional array corresponding to the execution path of the target test case, wherein the number of elements in the array is the same as the number of nodes in the multi-branch tree graph; The target program is run based on the target test case, and each node executed by the target test case during the running process is determined through the stub function, and a one-dimensional array corresponding to the execution path of the target test case is assigned to obtain an execution array corresponding to the execution path of the target test case.

7. The method according to claim 6, characterized in that According to the importance of each node in the target path set, any target path and the execution path of the target test case, an evaluation result of the target test case is obtained by calculating through an evaluation function, including: According to the importance of each node, the target array corresponding to any target path and the execution array corresponding to the execution path of the target test case, the evaluation result of the target test case is calculated by the evaluation function; The calculation formula of the evaluation function is: Wherein, F(a) is the evaluation result of the target test case a; D(a) is the sum of the branch distances of the target test case a; is the importance of node Ri; is the value of the node Ri in the execution array; is the value of the node Ri in the target array; i is the node index; n is the total number of nodes.

8. A device for generating evaluation results of a test case, characterized in that: The device comprises: A first acquisition module is used to acquire a target path set of a target program; A second acquisition module is used to run the target program based on a target test case corresponding to any target path of the target program to acquire an execution path of the target test case; An evaluation result generation module is used to obtain the evaluation result of the target test case through evaluation function calculation according to the importance of each node in the target path set, any target path and the execution path of the target test case; wherein any node represents the code line in the target program, and the importance represents the contribution of any node to the target path set.

9. A computer device, characterized in that: include: At least one processor, and a memory, wherein the memory stores a computer program that can be run on the processor, wherein when the processor executes the computer program, the method for generating evaluation results of the test case according to any one of claims 1 to 7 is executed.

10. A non-volatile readable storage medium, characterized in that: The non-volatile readable storage medium stores a computer program, wherein the computer program, when executed by a processor, executes the method for generating evaluation results of a test case according to any one of claims 1 to 7.