Software fault positioning method based on test case and statement importance
By building a weighted association rule network, using Jaccard metrics and centrality to evaluate the importance of statements, optimizing suspicion calculations, the problem of inaccurate software fault location is solved and the accuracy of fault location is improved.
Patent Information
- Application Number
- CN202410117971.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-29
- Publication Date
- 2025-08-01
AI Technical Summary
Existing software fault positioning techniques have problems with inaccurate positioning, especially due to inaccurate positioning caused by element binding and incomprehensibility of deep learning.
By building a weighted association rules network, the Jaccard measurement method is used to measure the importance of test cases, calculate the correlation between nodes and edges, combine the centrality of the eigenvectors of complex networks to evaluate the importance of statements, and optimize the skepticism calculation to improve the accuracy of fault location.
On the basis of considering the importance of test cases and statements, optimize the skepticism calculation, solve the element binding problem, and improve the accuracy of software failure location.
Smart Images

Figure CN120407386A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular, to a software fault localization method based on test cases and statement importance. Background Art
[0002] As the complexity and scale of software systems increase day by day, the existence of software faults may bring irreparable losses, especially for safety-critical software. However, software testing work is a recognized time-consuming and laborious challenge, and developers have to spend a large amount of costs on this work, making software testers consume a lot of time and energy to manually check program elements to find the exact fault location.
[0003] Spectrum-Based Fault Localization (SBFL) technology has been widely concerned by researchers due to its ease of use and high efficiency. It mainly uses statistical analysis or machine learning and other technologies to evaluate the possibility of a statement having a fault. If the frequency of a statement in failing test cases is higher than its frequency in passing test cases, then the statement is more worthy of suspicion. This also represents the suspicion degree of each statement. The higher the value of the suspicion degree, the greater the possibility that the statement has a fault. However, the method based on statistical analysis mainly relies on the correlation calculation between statement coverage information and test case execution results. Therefore, the code of the same program block will share the same suspicion degree, which is also called element binding.
[0004] Existing deep learning-based SBFL takes statements as features and alleviates the problem of element binding by increasing the discrimination of statements and evaluating statement importance. However, the incomprehensibility of deep learning affects its practical application value. In addition, the prior art ignores the importance of test cases and statements, resulting in inaccurate fault localization. Summary of the Invention
[0005] In view of the above analysis, embodiments of the present invention aim to provide a software fault localization method based on test cases and statement importance to solve the problem of inaccurate existing software fault localization.
[0006] Embodiments of the present invention provide a software fault localization method based on test cases and statement importance, including the following steps:
[0007] Construct transaction data according to the program statements covered by test cases in the program spectrum and the execution results of test cases, and calculate the weights of each transaction data through the Jaccard metric method;
[0008] Obtain atomic association rules from each transaction data. Take each program statement as a node, and based on the atomic association rules and the weights of each transaction data, calculate the correlation between the node and the failed execution result as the node weight; calculate the correlation between nodes as the edge weight; construct a weighted association rule network according to the nodes, node weights, and edge weights.
[0009] Calculate the eigenvector centrality of each node in the weighted association rule network as the node importance. According to the node importance and node weight, obtain the weighted suspicion degree of the node; output the program statements corresponding to each node in descending order of the weighted suspicion degree, and perform software fault localization in sequence.
[0010] Based on a further improvement of the above method, calculate the weights of each transaction data through the Jaccard metric method, including: each transaction data is divided into failed transactions and passed transactions according to the execution results of test cases. Calculate the Jaccard distance between each failed transaction and each passed transaction through the Jaccard metric method, and take the failed transaction corresponding to the longest Jaccard distance as the most important failed transaction; calculate the Jaccard similarity coefficient between each passed transaction and the most important failed transaction as the weight of the passed transaction; set the weight of each failed transaction to 1.
[0011] Based on a further improvement of the above method, each failed transaction and passed transaction includes at least one program statement and a corresponding execution result; when calculating the Jaccard distance and Jaccard similarity coefficient, remove the execution results in the failed transaction and passed transaction.
[0012] Based on a further improvement of the above method, obtaining atomic association rules from each transaction data is by using a data mining algorithm, setting both the minimum support threshold and the minimum confidence threshold to 0 to obtain association rules of length 2.
[0013] Based on a further improvement of the above method, when calculating the support degree of the atomic association rules or any item in the transaction data based on the weights of each transaction data, the weighted support degree is obtained by calculating the ratio of the sum of the weights of the transaction data containing the atomic association rules or this item to the sum of the weights of all transaction data.
[0014] Based on a further improvement of the above method, calculating the correlation between the node and the failed execution result as the node weight is for the atomic association rules where the antecedent is a program statement and the consequent is a failed execution result. By using the Barinel, Ochiai, or Dstar suspicion degree formula, calculate the suspicion degree as the node weight according to the weighted support degree.
[0015] Based on the further improvement of the above method, the correlation between computing nodes is calculated as the edge weight. For an atomic association rule where both the antecedent and the consequent are program statements, the probability of the antecedent and the consequent appearing simultaneously in the transaction data is calculated according to the weighted support, and the sum of the probability of the antecedent and the consequent not appearing simultaneously is used as the edge weight between nodes.
[0016] Based on the further improvement of the above method, the edge weight is calculated by the following formula:
[0017]
[0018] Wherein, represents the atomic association rule the edge weight between the antecedent node A and the consequent node B in, W SUP (A∪B) represents the weighted support of nodes A and B appearing simultaneously in the transaction data, represents the weighted support of nodes A and B not appearing simultaneously in the transaction data.
[0019] Based on the further improvement of the above method, the weighted association rule network is an undirected weighted network constructed according to the atomic association rule where both the antecedent and the consequent are program statements.
[0020] Based on the further improvement of the above method, according to the node importance and the node weight, the weighted suspicion degree of the node is obtained by taking the product of the node importance and the node weight as the weighted suspicion degree of the node.
[0021] Compared with the prior art, the present invention can at least achieve one of the following beneficial effects: measuring the importance of test cases through the Jaccard metric method, realizing the mining of weighted association rules, constructing a complex network by calculating the correlation between statements and between statements and the execution results of test cases, and evaluating the importance of statements using the eigenvector centrality of the complex network. Finally, on the basis of considering both the importance of test cases and the importance of statements, the suspicion degree calculation is optimized to solve the element binding problem and improve the accuracy of fault location.
[0022] In the present invention, the above technical solutions can also be combined with each other to achieve more preferred combination schemes. Other features and advantages of the present invention will be described in the following specification, and some advantages can be made obvious from the specification, or can be understood by implementing the present invention. The objectives and other advantages of the present invention can be achieved and obtained through the content specifically pointed out in the specification and the drawings. Description of the Drawings
[0023] The drawings are only used for the purpose of showing specific embodiments, and are not considered as limiting the present invention. Throughout the drawings, the same reference signs represent the same components.
[0024] Figure 1 Flowchart of a software fault localization method based on test cases and statement importance in an embodiment of the present invention;
[0025] Figure 2 Architecture diagram of a software fault localization method based on test cases and statement importance in an embodiment of the present invention. Detailed implementation manners
[0026] The following will specifically describe the preferred embodiments of the present invention with reference to the accompanying drawings. The accompanying drawings form a part of this application and are used together with the embodiments of the present invention to explain the principles of the present invention, rather than to limit the scope of the present invention.
[0027] A specific embodiment of the present invention discloses a software fault localization method based on test cases and statement importance. As shown in Figure 1 and Figure 2 , it includes the following steps:
[0028] S1. Construct transaction data according to the program statements covered by the test cases in the program spectrum and the execution results of the test cases, and calculate the weights of each transaction data through the Jaccard measurement method;
[0029] S2. Obtain atomic association rules from each transaction data. Take each program statement as a node, and based on the atomic association rules and the weights of each transaction data, calculate the correlation between the node and the failed execution result as the node weight; calculate the correlation between nodes as the edge weight; construct a weighted association rule network according to the nodes, node weights, and edge weights;
[0030] S3. Calculate the eigenvector centrality of each node in the weighted association rule network as the node importance. According to the node importance and the node weight, obtain the weighted suspicion degree of the node; output the program statements corresponding to each node from large to small according to the weighted suspicion degree, and perform software fault localization in turn.
[0031] During implementation, in step S1, the Jaccard method is used to assign weight values to different transaction data to reflect the importance of test cases. In step S2, the association relationship between statements is mined from the transaction data to obtain atomic association rules. The suspicion degree between the node and the failed execution result is used as the node weight (i.e., the initial suspicion degree), and the correlation between nodes is used as the edge weight to construct a complex network. In step S3, the eigenvector centrality of the complex network is used to represent the statement importance, and the initial suspicion degree of the node is optimized with the statement importance as the weight, so that the optimized suspicion degree in this embodiment takes into account both the importance of test cases and statement importance, thereby increasing the contribution degree of different program statements to the fault, solving the problem of element binding, and improving the accuracy of fault localization.
[0032] It should be noted that in step S1, this embodiment uses the GZoltar tool to collect the coverage information and execution results of the application program in the test cases, and generates a program spectrum. In the program spectrum, 0 and 1 represent the coverage information of each program statement in the source code in the test cases, 0 means not covered, 1 means covered, and Pass and Fail respectively represent that the execution results of the test cases are passed and failed.
[0033] When constructing transaction data, only the program statements covered in the test cases, that is, the program statements with 1 in the program spectrum, and the execution results are required. One test case corresponds to one transaction data, one program statement represents one item, and one transaction data includes at least one program statement and a corresponding execution result.
[0034] Exemplarily, there are 6 program statements Statement1~Statement6, and the program spectra corresponding to two test cases are: Then the two transaction data Trans1 and Trans2 constructed are:
[0035]
[0036] Furthermore, considering that the program statements included in the test cases with failed execution are more likely to have faulty statements than those with passed execution, therefore, this embodiment calculates the weights of each transaction data through the Jaccard metric method to characterize the importance of different test cases.
[0037] Specifically, each transaction data is divided into a failed transaction and a passed transaction according to the execution result of the test case. The Jaccard distance between each failed transaction and each passed transaction is calculated through the Jaccard metric method, and the failed transaction corresponding to the longest Jaccard distance is taken as the most important failed transaction; the Jaccard similarity coefficient between each passed transaction and the most important failed transaction is calculated respectively as the weight of the passed transaction; the weight of each failed transaction is set to 1.
[0038] It should be noted that each failed transaction and passed transaction includes at least one program statement and a corresponding execution result; when calculating the Jaccard distance and Jaccard similarity coefficient, the execution results in the failed transaction and passed transaction are removed, and only the covered program statements are considered. The Jaccard distance is the complement of the Jaccard similarity coefficient and is defined as 1 minus the Jaccard similarity coefficient; the Jaccard similarity coefficient is used to represent the similarity between the test cases (transactions) with failed execution and passed execution. It represents the proportion of the total number of identical statements included in two test cases to the total number of all statements. The formula is as follows:
[0039]
[0040] Among them, represents the Jaccard similarity coefficient of the i-th transaction passing through transaction Trans Pi , that is, the weight; Trans F represents the most important failed transaction.
[0041] In step S2, obtaining the atomic association rules from each transaction data is to obtain the association rules of length 2 by adopting a data mining algorithm according to the set minimum support threshold and minimum confidence threshold. Preferably, in this embodiment, in order to retain all program statements in the generated association rules so as to sort all program statements, the minimum support threshold and minimum confidence threshold are set to 0 to generate atomic association rules, which is equivalent to combining any two items in each transaction data to obtain atomic association rules. The length of the atomic association rule being 2 means that both the antecedent and the consequent are one item.
[0042] It should be noted that since each transaction data has a corresponding weight, when calculating the support of the atomic association rule or any item in the transaction data, the weighted support is obtained by calculating the ratio of the sum of the weights of the transaction data containing the atomic association rule or the item to the sum of the weights of all transaction data. The formula is as follows:
[0043]
[0044] Among them, represents the weighted support of the atomic association rule , represents the sum of the weights of the transaction data that simultaneously contains A and B, where represents the k-th transaction data Trans k simultaneously contains A and B, ∑Jaccard Trans represents the sum of the weights of all transaction data; W SUP (A) represents the weighted support of any item in the transaction data, where any item is a program statement or an execution result; represents the sum of the weights of the transaction data that contains A, where represents the r-th transaction data Trans r contains A.
[0045] Furthermore, in order to analyze the association relationship of the atomic association rules, in this embodiment, each program statement is used as a node to construct a complex association rule network, and the contribution of each program statement to the fault is represented by the node weight, and the relevance between program statements is represented by the edge weight.
[0046] Specifically, the node weight is the correlation between a node and a failed execution result, which is an atomic association rule where the antecedent is a program statement and the consequent is a failed execution result. By adopting the Barinel, Ochiai, or Dstar suspicion formula, the suspicion degree calculated based on the weighted support is used as the node weight.
[0047] It should be noted that the Barinel, Ochiai, and Dstar suspicion formulas are as follows:
[0048]
[0049] Among them, W n (Barinel), W n (Ochiai), and W n (Dstar) respectively represent the initial suspicion degree of the nth node calculated using the Barinel, Ochiai, and Dstar suspicion formulas, that is, the node weight; Fail represents the failed execution result, which is the consequent of the atomic association rule; W SUP (·) represents the weighted support calculated using formula (2); * represents a variable greater than 0, and preferably, * takes 2.
[0050] It should be noted that there are a large number of program statements in the test cases. Each test case can be understood as a software execution path, and there is a context relationship among the elements in the path. Therefore, the program statements that appear simultaneously in a test case can be considered to have a direct or indirect call relationship. Additionally, usually, the number of test cases that execute and fail is very small, and the program statements that commonly appear in the failed test cases rarely appear simultaneously in the passed test cases. Therefore, in this embodiment, when calculating the correlation between nodes and obtaining the edge weight, the probabilities of two program statements appearing and not appearing simultaneously in the test cases are considered simultaneously, amplifying the co-occurrence relationship between the two program statements.
[0051] Specifically, for an atomic association rule where both the antecedent and the consequent are program statements, the probability of the antecedent and the consequent appearing simultaneously in the transaction data is calculated based on the weighted support, and the sum of the probabilities of the antecedent and the consequent not appearing simultaneously is used as the edge weight between nodes. The formula is as follows:
[0052]
[0053] Among them, represents the edge weight between the antecedent node A and the consequent node B in the atomic association rule , W SUP (A∪B) represents the weighted support of nodes A and B appearing simultaneously in the transaction data, represents the weighted support of nodes A and B not appearing simultaneously in the transaction data.
[0054] Based on nodes, node weights, and edge weights, constructing a weighted association rule network is an undirected weighted network constructed according to atomic association rules where both the antecedent and the consequent are program statements.
[0055] Next, in step S3, the theory of complex networks is used to analyze the impact of program statements on faults. Node importance is a method for quantifying the importance of components in a network structure, mainly including degree centrality and eigenvector centrality. Degree centrality uses the number of edges connected to a node as a measure of node importance. In a weighted undirected network, degree centrality is the sum of the weights of the edges connected to the node. However, degree centrality ignores the importance of neighbor nodes. Although the correlation between the target node and neighbor nodes connected by edges with larger weights is stronger, the contribution of neighbor nodes to faults may be very low, which directly leads to deviations in the calculation results.
[0056] Therefore, in order to more effectively quantify the contribution degree of nodes (program statements) to faults, this embodiment simultaneously considers the edge weights of nodes and the importance of adjacent nodes, and uses eigenvector centrality to calculate node importance. The specific formula is as follows:
[0057]
[0058] where EC(n p ) represents the eigenvector centrality of node n p , N represents the total number of neighbor nodes of node n p , n q represents a neighbor node of node n p , represents the edge weight between node n p and node n q calculated by formula (4), represents the node weight of node n q calculated by any one of the suspicion degree formulas in formula (3), and c represents a proportionality constant, usually set to 1.
[0059] Finally, based on node importance and node weight, the weighted suspicion degree of a node is obtained by taking the product of node importance and node weight as the weighted suspicion degree of the node. That is to say, this embodiment uses the importance of a program statement (node importance) as the weight of the initial suspicion degree (node weight) of the program statement. This way means that if a program statement may induce a fault, then the program statements related to this program statement in the test case are more likely to be suspected.
[0060] Specifically, the formula for weighted suspicion degree is as follows:
[0061]
[0062] Among them, SP(n p ) represents the weighted suspicion degree of node n p , and EC(n p ) represents the node importance of node n p . represents the node weight of node n p .
[0063] Calculate the weighted suspicion degree of each node according to formula (6), output the program statements corresponding to each node from largest to smallest weighted suspicion degree, and perform software fault localization in sequence.
[0064] Compared with the prior art, a software fault localization method based on test cases and statement importance provided in this embodiment measures the importance of test cases through the Jaccard metric method, realizes the mining of weighted association rules, calculates the correlation between statements and between statements and test case execution results, constructs a complex network, and uses the eigenvector centrality of the complex network to evaluate the importance of statements. Finally, the suspicion degree calculation is optimized on the basis of considering both the importance of test cases and statement importance, the element binding problem is solved, and the accuracy of fault localization is improved.
[0065] Those skilled in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. Among them, the computer-readable storage medium is a magnetic disk, an optical disk, a read-only memory or a random access memory, etc.
[0066] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present invention should be covered by the protection scope of the present invention.
Claims
1. A software fault localization method based on test cases and statement importance, characterized in that, The steps include: Construct transaction data based on the program statements covered by test cases in the program spectrum and the execution results of the test cases, and calculate the weights of each transaction data through the Jaccard measurement method; Obtain atomic association rules from the above-mentioned transaction data, use each program statement as a node, and calculate the correlation between the node and the failed execution result as the node weight based on the atomic association rules and the weights of each transaction data; Calculate the correlation between the nodes as the edge weight; Construct a weighted association rule network according to the nodes, node weights, and edge weights; Calculate the eigenvector centrality of each node in the weighted association rule network as the node importance, and obtain the weighted suspicion degree of the node according to the node importance and the node weight; output the program statements corresponding to each node from large to small according to the weighted suspicion degree, and perform software fault localization in turn.
2. The software fault localization method based on test cases and statement importance according to claim 1, wherein The calculation of the weights of each transaction data through the Jaccard measurement method includes: each transaction data is divided into failed transactions and passed transactions according to the execution results of the test cases, calculate the Jaccard distance between each failed transaction and each passed transaction through the Jaccard measurement method, and take the failed transaction corresponding to the longest Jaccard distance as the most important failed transaction; calculate the Jaccard similarity coefficient between each passed transaction and the most important failed transaction respectively as the weight of the passed transaction; the weight of each failed transaction is set to 1.
3. The software fault localization method based on test cases and statement importance according to claim 2, wherein Each of the failed transactions and the passed transactions includes at least one program statement and a corresponding execution result; when calculating the Jaccard distance and Jaccard similarity coefficient, the execution results in the failed transactions and passed transactions are removed.
4. The software fault localization method based on test cases and statement importance according to claim 1, characterized in that, Obtaining atomic association rules from each transaction data is to obtain association rules of length 2 by using a data mining algorithm and setting both the minimum support threshold and the minimum confidence threshold to 0.
5. The software fault localization method based on test cases and statement importance according to claim 2, characterized in that When calculating the support of the atomic association rules or the support of any item in the transaction data based on the weights of each transaction data, the weighted support is obtained by calculating the ratio of the sum of the weights of the transaction data containing the atomic association rules or the item to the sum of the weights of all transaction data.
6. The software fault location method based on test cases and statement importance according to claim 5, characterized in that The calculation of the correlation between the node and the failed execution result as the node weight is to use the Barinel, Ochiai, or Dstar suspicion formula for the atomic association rules whose antecedent is a program statement and the consequent is a failed execution result, and calculate the suspicion degree as the node weight according to the weighted support.
7. The software fault localization method based on test cases and statement importance according to claim 5, characterized in that The calculation of the correlation between the nodes as the edge weight is to calculate the probability that the antecedent and the consequent both appear in the transaction data for the atomic association rules whose antecedent and consequent are both program statements, and the sum of the probabilities that the antecedent and the consequent do not appear at the same time as the edge weight between the nodes.
8. The software fault localization method based on test cases and statement importance according to claim 7, characterized in that, The edge weight is calculated by the following formula: Among them, represents the edge weight, W, between the antecedent node A and the consequent node B in the atomic association rule SUP (A∪B) represents the weighted support for the simultaneous occurrence of nodes A and B in the transaction data, and represents the weighted support for the non - simultaneous occurrence of nodes A and B in the transaction data.
9. The software fault localization method based on test cases and statement importance according to claim 1, characterized in that The weighted association rule network is an undirected weighted network constructed according to the atomic association rules whose antecedent and consequent are both program statements.
10. The software fault localization method based on test cases and statement importance according to any one of claims 1-9, characterized in that, The weighted suspicion degree of a node obtained according to the node importance and the node weight is the product of the node importance and the node weight as the weighted suspicion degree of the node.