A path-based test case priority sequence recommendation method and system
By generating test path feature vectors and using the XGBoost algorithm to train a fault prediction model, the problem of inaccurate test case priority ranking in traditional methods is solved, achieving reasonable ranking of test case priorities and improving testing efficiency and quality.
Patent Information
- Application Number
- CN202510534896.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2045-04-27
AI Technical Summary
Traditional methods for determining test case priorities fail to adequately consider path changes before and after program version updates, as well as the correlation between paths and faults. This results in inaccurate test case priority ranking, inability to effectively cover potentially faulty paths, and negatively impacts test performance.
The path-based test case priority sequence recommendation method obtains test execution information from both new and old versions of the program, generates test path feature vectors, trains a fault prediction model using the XGBoost algorithm, determines the predicted fault probability of basic coverage paths in the new version of the program, filters fault coverage paths based on the predicted fault probabilities, calculates the target association score between test coverage paths and fault coverage paths, and generates a priority recommendation sequence.
It achieves a reasonable prioritization of test cases, improves the accuracy of test case priority ranking, effectively covers paths where failures may occur, and improves testing efficiency and quality.
Smart Images

Figure CN120448267B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software testing technology, and in particular to a path-based test case priority sequence recommendation method and system. Background Technology
[0002] In the field of software testing, with the continuous updates of software versions, how to efficiently determine the priority of test cases and improve testing efficiency and quality is an important technical problem we are currently facing.
[0003] Traditional methods for determining test case priorities often fail to adequately consider path changes before and after program version updates, as well as the correlation between paths and faults. This results in inaccurate test case priority ranking, inability to effectively cover potentially faulty paths, and severely impacts test performance.
[0004] Therefore, it is necessary to provide a path-based test case priority sequence recommendation method and system to solve the above-mentioned technical problems. Summary of the Invention
[0005] To address the aforementioned technical problems, this invention provides a path-based test case priority sequence recommendation method and system, which solves the problems that traditional test case priority sequence recommendation methods cannot effectively cover fault paths and have insufficient accuracy.
[0006] This invention provides a path-based test case priority sequence recommendation method, the recommendation method comprising:
[0007] Obtain test execution information for the target test cases based on both the new and old versions of the program;
[0008] Based on the test execution information, values are assigned to the positions of each node in the test coverage path of the target test case to generate a test path feature vector;
[0009] Based on the XGBoost algorithm, a fault prediction model is trained using the feature vector of the test path and the program execution result in the target test case as input and output, respectively.
[0010] Based on the fault prediction model, the predicted fault probability of the basic coverage path in the new version of the program is determined, and the fault coverage path is obtained by filtering based on the predicted fault probability.
[0011] Based on preset recommendation rules, the target association score between the test coverage path and the fault coverage path in each target test case is calculated. The target test cases are then arranged in descending order of the target association score to generate a priority recommendation sequence.
[0012] Preferably, after obtaining the test execution information, compare the control flow graphs of the new version program and the old version program;
[0013] Based on the edit distance algorithm, calculate the edit distance between each pair of nodes in the control flow graphs of the new version program and the old version program;
[0014] If the edit distance is 0, mark the node as an unchanged node;
[0015] If the edit distance is not 0 and the node only exists in the new version program, mark the node as an added node;
[0016] If the edit distance is not 0 and the node only exists in the old version program, mark the node as a deleted node.
[0017] Preferably, based on the test execution information, obtain the length of the longest path in the test coverage path as the dimension of the test path feature vector. Then, the value at the position of the unchanged node is 1; the value at the position of the added node is 3; the value at the position of the deleted node is 2; and the value at the position of the remaining nodes in the test coverage path is 0;
[0018] Generate the test path feature vector based on the values assigned to the unchanged nodes, added nodes, deleted nodes, and remaining nodes.
[0019] Preferably, before training the fault prediction model using the XGBoost algorithm, with the test path feature vector and the program execution result in the target test case as input and output respectively, use the principal component analysis technique to perform dimensionality reduction on the test path feature vector, that is, reduce the dimension of the test path feature vector from D to D′, where D′ < D, specifically including:
[0020] Perform standardization on the test path feature vector until the mean of all the test path feature vectors is 0 and the variance is 1;
[0021] Calculate the covariance matrix C corresponding to the test path feature vector ;
[0022] Solve the matrix eigenvalues and matrix eigenvectors of the covariance matrix C;
[0023] Arrange all the matrix eigenvalues from largest to smallest, and select the matrix eigenvectors corresponding to the first D′ matrix eigenvalues to form the projection matrix W;
[0024] The test path feature vector Projecting the vectors onto the projection matrix W yields the dimensionality-reduced feature vector of the test path. Furthermore, the dimensionality-reduced feature vector of the test path The dimension is D′.
[0025] Preferably, the step of determining the predicted fault probability of the basic coverage path in the new version of the program based on the fault prediction model, and filtering out fault coverage paths based on the predicted fault probability, specifically includes:
[0026] The McCabe cyclic complexity algorithm is used to extract the basic coverage path in the new version of the program.
[0027] The positions of each node in the basic coverage path are assigned values to generate a basic path feature vector, which is then input into the fault prediction model.
[0028] Based on the fault prediction model, the sigmoid function is used to transform the basic path feature vector into the predicted fault probability.
[0029] A preset fault path ratio of Y% is obtained. All predicted fault probabilities are sorted from largest to smallest, and the basic coverage paths corresponding to the top Y% of the predicted fault probabilities are selected as the fault coverage paths.
[0030] Preferably, the step of calculating the target association score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules specifically includes:
[0031] For any of the fault coverage paths, if the value at any node position in the fault coverage path is 1, and the value at any node position in the test coverage path is 1 or 3, then the first sub-association score corresponding to the test coverage path is 1.
[0032] If the value assigned to any node in the fault coverage path is 2, and the value assigned to any node in the test coverage path is 1 or 3, then the first sub-association score corresponding to the test coverage path is 2.
[0033] Apart from the two assignment scenarios mentioned above, the score of the first sub-association is 0 in all other assignment scenarios.
[0034] Preferably, the first sub-association scores corresponding to all test coverage paths in the target test case are summarized to obtain the first association score corresponding to any fault coverage path;
[0035] The target association score is obtained by combining the first association scores corresponding to all the fault coverage paths.
[0036] A path-based test case priority sequence recommendation system, the recommendation system comprising:
[0037] The information acquisition module is used to acquire test execution information of the target test cases based on the new version of the program and the old version of the program;
[0038] The position assignment module is used to assign values to the positions of each node in the test coverage path of the target test case based on the test execution information, and generate a test path feature vector.
[0039] The model training module is used to train a fault prediction model based on the XGBoost algorithm, with the feature vector of the test path and the program execution result in the target test case as input and output, respectively.
[0040] The fault prediction module is used to determine the predicted fault probability of the basic coverage path in the new version of the program based on the fault prediction model, and to filter out the fault coverage path based on the predicted fault probability.
[0041] The sequence generation module is used to calculate the target association score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, and arrange the target test cases in descending order of the target association score to generate a priority recommendation sequence.
[0042] An electronic device includes a memory and a processor, wherein the memory stores a computer program, and when the processor runs the computer program stored in the memory, the processor performs the steps of a path-based test case priority sequence recommendation method as described in any of the preceding claims.
[0043] A readable storage medium storing a computer program, which, when executed by a processor, is used to implement the steps of a path-based test case priority sequence recommendation method as described in any of the preceding claims.
[0044] Compared with related technologies, the path-based test case priority sequence recommendation method and system provided by this invention have the following beneficial effects:
[0045] This invention can obtain test execution information of target test cases based on both new and old versions of the program; based on the test execution information, it assigns values to the positions of each node in the test coverage path of the target test cases to generate test path feature vectors; based on the XGBoost algorithm, it trains a fault prediction model using the test path feature vectors and the program execution results in the target test cases as input and output, respectively; based on the fault prediction model, it determines the predicted fault probability of the basic coverage path in the new version of the program, and selects fault coverage paths based on the predicted fault probabilities; based on preset recommendation rules, it calculates the target association score between the test coverage path and the fault coverage path in each target test case, and arranges the target test cases according to the target association score from largest to smallest to generate a priority recommendation sequence, thereby effectively covering fault paths and improving the accuracy of test case priority ranking.
[0046] This invention compares the control flow graphs of old and new program versions, marks node changes, generates test path feature vectors, and uses the XGBoost algorithm to train a fault prediction model. This allows for accurate prediction of the fault probability of basic coverage paths in the new program version, thus identifying faulty coverage paths. Based on this, by calculating the target association score between test coverage paths and faulty coverage paths, a reasonable prioritization of test cases is achieved. This method fully considers program path changes and fault associations, improves the accuracy of test case prioritization, effectively covers potentially faulty paths, and enhances testing efficiency and quality. Attached Figure Description
[0047] Figure 1 A flowchart illustrating a path-based test case priority sequence recommendation method provided in an embodiment of the present invention;
[0048] Figure 2 A system block diagram of a path-based test case priority sequence recommendation system provided in an embodiment of the present invention;
[0049] Figure 3 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0051] like Figure 1The diagram shown is a flowchart of a path-based test case priority sequence recommendation method provided by an embodiment of the present invention. Figure 1 The execution entity of the method shown can be a software and / or hardware device. The execution entity of this application can include, but is not limited to, at least one of the following: user equipment, network equipment, etc. User equipment can include, but is not limited to, computers, smartphones, personal digital assistants (PDAs), and the aforementioned electronic devices. Network equipment can include, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of computers or network servers. Cloud computing is a type of distributed computing, consisting of a super virtual computer composed of a group of loosely coupled computers. This embodiment does not limit this. Steps S1 to S5 are detailed as follows:
[0052] S1, Obtain test execution information for the target test cases based on the new and old versions of the program;
[0053] In software testing scenarios, target test cases refer to pre-designed combinations of specific inputs and expected outputs used to verify the compliance of program functions.
[0054] By deploying the target test cases in both new and old versions of the program, response data for the same test cases in both types of programs can be collected, namely test execution information, which includes dynamic runtime characteristics such as program control flow trajectory, node execution status, correctness of output results, and exception throwing records.
[0055] S2, based on the test execution information, assign values to the positions of each node in the test coverage path of the target test case to generate a test path feature vector;
[0056] Understandably, based on test execution information, by assigning values to the positions of each node in the test coverage path of the target test case, the information of the test path can be transformed into a feature vector that can be processed by machine learning algorithms. Furthermore, the assignment of node positions is based on changes to the nodes in the program control flow graph.
[0057] During software version updates, nodes in the program control flow graph may remain unchanged, be added, or be deleted. To accurately reflect these changes, different values can be assigned to different types of nodes. Specifically, an unchanged node is assigned a value of 1, indicating that the node remains unchanged in both the old and new versions of the program and is a relatively stable part of the program; a newly added node is assigned a value of 3, because the added node represents new logic or functionality in the new version of the program and may be a potential area for failure; a deleted node is assigned a value of 2, indicating that the node existed in the old version but has been deleted in the new version, and this change may also affect the overall functionality of the program; and the remaining nodes in the test coverage path are assigned a value of 0, as these nodes may not be closely related to the focus of this test.
[0058] Based on the node assignments described above, a test path feature vector can be generated. This feature vector mathematically represents the information of the test path, facilitating subsequent processing by machine learning algorithms. The dimension of the test path feature vector is typically determined by the length of the longest path in the test coverage path, providing a comprehensive description of the test path's structure and node changes.
[0059] S3, based on the XGBoost algorithm, the fault prediction model is trained with the feature vector of the test path and the program execution result in the target test case as input and output, respectively.
[0060] It should be noted that XGBoost (eXtreme Gradient Boosting) is a powerful machine learning algorithm based on the Gradient Boosting Decision Tree (GBDT) framework. It iteratively trains multiple weak classifiers and combines them into a strong classifier. Due to its efficiency, accuracy, and scalability, XGBoost can handle large-scale datasets and complex feature relationships; therefore, in this method, it is used to train the fault prediction model.
[0061] Furthermore, the fault prediction model is trained using the test path feature vector as input and the program execution result in the target test case as output. The program execution result can be categorized into two cases: fault occurrence and no fault occurrence. Through extensive training data, the fault prediction model learns the relationship between test path features and fault occurrence. Moreover, during training, the model continuously adjusts its parameters to minimize the error between the predicted and actual results.
[0062] S4. Based on the fault prediction model, determine the predicted fault probability of the basic coverage path in the new version of the program, and filter out the fault coverage path based on the predicted fault probability.
[0063] The basic coverage path is a simplified representation of all possible execution paths in the program, extracted using the McCabe cyclic complexity algorithm. Then, the basic coverage path can be transformed into a basic path feature vector and input into a fault prediction model. This model, based on the previously learned relationship between features and faults, uses a sigmoid function to convert the basic path feature vector into a predicted fault probability. The predicted fault probability reflects the likelihood of a fault occurring during the execution of that path.
[0064] To concentrate testing resources and improve testing efficiency, it is necessary to select fault coverage paths based on predicted fault probabilities. The default fault path percentage is Y%. All basic coverage paths are ranked from highest to lowest predicted fault probability, and the top Y% of basic coverage paths are selected as fault coverage paths. These paths are the most likely to experience faults, and focusing testing on them can more effectively uncover software problems.
[0065] S5. Based on preset recommendation rules, calculate the target association score between the test coverage path and the fault coverage path in each target test case, and arrange the target test cases in descending order of the target association score to generate a priority recommendation sequence.
[0066] Understandably, the target association score reflects the degree of coverage of test cases for paths that may have faults. Specifically, the first sub-association score is determined based on the node positions assigned in both the faulty coverage path and the test coverage path. Then, by aggregating the first sub-association scores corresponding to all test coverage paths, the first association score for any faulty coverage path can be obtained. Finally, by combining the first association scores of all faulty coverage paths, the target association score is obtained.
[0067] Furthermore, target test cases can be ranked from highest to lowest according to their target correlation scores to generate a priority recommendation sequence. Test cases with higher target correlation scores indicate better coverage of fault paths and are more likely to discover software faults; therefore, they should be executed first. This prioritization allows testers to focus limited testing resources on test cases most likely to find problems, improving the targeting and efficiency of testing.
[0068] By comparing old and new versions of the program, extracting test path features, training a fault prediction model, filtering fault coverage paths, and calculating correlation scores to generate a priority sequence, this approach fully considers path changes and the likelihood of faults during program version updates. This allows for a more scientific arrangement of test case execution order, thereby improving the efficiency and quality of software testing and reducing the risk of faults after software release. In practical applications, parameters such as the preset fault path percentage (Y%) can be adjusted according to different software project characteristics and testing requirements to achieve optimal testing results.
[0069] In the specific implementation process, after obtaining the test execution information, the control flow graphs of the new version program and the old version program are compared;
[0070] Based on the edit distance algorithm, the edit distance between each node in the control flow graph of the new version program and the old version program is calculated;
[0071] If the edit distance is 0, then the node is marked as an unchanged node;
[0072] If the edit distance is not 0, and the node exists only in the new version of the program, then the node is marked as a new node;
[0073] If the edit distance is not 0, and the node only exists in the old version of the program, then the node is marked as a deleted node.
[0074] After obtaining the test execution information, it is necessary to compare the control flow graphs of the two versions of the program. A control flow graph is a graphical representation used to describe the program execution flow. By comparing the control flow graphs, the structural and logical changes during program version updates can be clearly understood.
[0075] To accurately identify changes to nodes in the control flow graph, an edit distance algorithm can be used to calculate the minimum number of operations required to convert between two strings through insertion, deletion, and replacement. In this scenario, it is used to calculate the edit distance between nodes in the control flow graphs of the new and old versions of the program.
[0076] Then, nodes can be categorized and labeled based on the calculated edit distance. If the edit distance is 0, it means the node has not changed in the control flow graph of the old and new versions of the program, and this node will be marked as an unchanged node. If the edit distance is not 0, and the node only exists in the control flow graph of the new version of the program, it indicates that this node was added in the new version, and it will be marked as a new node. If the edit distance is not 0, and the node only exists in the control flow graph of the old version of the program, it indicates that this node has been deleted in the new version, and it will be marked as a deleted node. This labeling method can provide important basis for subsequent analysis of test paths and prediction of faults.
[0077] Based on the test execution information, the longest path length in the test coverage path is obtained as the dimension of the test path feature vector. Then, the value at the unchanged node position is 1; the value at the newly added node position is 3; the value at the deleted node position is 2; and the value at the remaining node positions in the test coverage path is 0.
[0078] The test path feature vector is generated based on the values assigned at the positions of the unchanged nodes, the newly added nodes, the deleted nodes, and the remaining nodes.
[0079] To effectively characterize the features of test coverage paths, it is necessary to construct test path feature vectors. First, based on test execution information, the length of the longest path in the test coverage path can be obtained and used as the dimension of the test path feature vector. This dimension setting ensures that the feature vector completely covers information from all test coverage paths.
[0080] Next, values can be assigned based on the different types of nodes. For unchanged nodes, since they remain stable in both the old and new versions of the program, a value of 1 is assigned to the corresponding position; newly added nodes represent new logic or functions in the new version of the program and are areas with high potential for failure, so a value of 3 is assigned; deleted nodes indicate that they have been removed in the new version, and their changes may affect the overall functionality of the program, so a value of 2 is assigned; and the remaining nodes in the test coverage path have a weak correlation with the current test focus, so a value of 0 is assigned.
[0081] Finally, based on the values assigned to unchanged nodes, newly added nodes, deleted nodes, and remaining nodes, a test path feature vector can be generated. This vector mathematically and precisely describes the structure and node changes of the test coverage path, providing crucial data support for subsequent analyses such as fault prediction using machine learning algorithms.
[0082] Before training the fault prediction model based on the XGBoost algorithm, using the test path feature vector and the program execution results in the target test cases as input and output respectively, principal component analysis is used to analyze the test path feature vector. Perform dimensionality reduction, that is, reduce the dimension of the test path feature vector from D to D′, where D' < D, specifically including:
[0083] Normalize the test path feature vector until the mean of all the test path feature vectors is 0 and the variance is 1;
[0084] Calculate the covariance matrix C corresponding to the test path feature vector ;
[0085] Solve the matrix eigenvalues and matrix eigenvectors of the covariance matrix C;
[0086] Arrange all the matrix eigenvalues from largest to smallest, select the matrix eigenvectors corresponding to the first D' matrix eigenvalues, and form a projection matrix W;
[0087] Project the test path feature vector onto the projection matrix W to obtain the dimension-reduced test path feature vector And the dimension of the dimension-reduced test path feature vector is D′.
[0088] Before training the fault prediction model using the XGBoost algorithm with the test path feature vector and the program execution result of the target test case as input and output, it is necessary to perform dimensionality reduction on the test path feature vector to reduce the data complexity and computational amount.
[0089] Specifically, first, it is necessary to normalize the test path feature vector so that the mean of all test path feature vectors is 0 and the variance is 1. Then, the covariance matrix corresponding to the test path feature vector can be calculated, the matrix eigenvalues and matrix eigenvectors of this covariance matrix can be solved, and all matrix eigenvalues can be arranged from largest to smallest, and the matrix eigenvectors corresponding to the first D' matrix eigenvalues are selected to form a projection matrix. Finally, the test path feature vector is projected onto the projection matrix to obtain the test path feature vector with reduced dimension.
[0090] Based on the fault prediction model, determine the predicted fault probability of the basic coverage path in the new version program, and screen out the fault coverage path based on the predicted fault probability, specifically including:
[0091] Adopt the McCabe cyclomatic complexity algorithm to extract the basic coverage path in the new version program;
[0092] Assign values to the positions of each node in the basic coverage path, generate a basic path feature vector and input it into the fault prediction model;
[0093] Based on the fault prediction model, the sigmoid function is used to transform the basic path feature vector into the predicted fault probability.
[0094] A preset fault path ratio of Y% is obtained. All predicted fault probabilities are sorted from largest to smallest, and the basic coverage paths corresponding to the top Y% of the predicted fault probabilities are selected as the fault coverage paths.
[0095] One approach is to use McCabe's cyclomatic complexity algorithm to extract the basic coverage paths in the new version of the program. This algorithm analyzes the program's control structure and identifies all possible independent execution paths, which constitute the set of basic coverage paths.
[0096] Next, values can be assigned to the positions of each node in the basic coverage path. Based on the characteristics of each node in the program, different values are assigned, thereby generating a feature vector for the basic path. This feature vector can comprehensively and accurately describe the characteristic information of the basic coverage path.
[0097] Subsequently, the basic path feature vector can be input into the fault prediction model, and the sigmoid function can be used to transform the basic path feature vector into the predicted fault probability. The sigmoid function can map the model's output to a range of 0 to 1, and the values in this range represent the probability of a fault occurring on the basic covered path.
[0098] Finally, a pre-defined percentage of faulty paths, Y%, can be obtained. All basic coverage paths are ranked from highest to lowest predicted fault probability, and the top Y% of basic coverage paths are selected as faulty coverage paths. These faulty coverage paths can then be tested intensively to efficiently discover potential faults in the software, improving testing efficiency and software quality.
[0099] The step of calculating the target association score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules specifically includes:
[0100] For any of the fault coverage paths, if the value at any node position in the fault coverage path is 1, and the value at any node position in the test coverage path is 1 or 3, then the first sub-association score corresponding to the test coverage path is 1.
[0101] If the value assigned to any node in the fault coverage path is 2, and the value assigned to any node in the test coverage path is 1 or 3, then the first sub-association score corresponding to the test coverage path is 2.
[0102] Apart from the two assignment scenarios mentioned above, the score of the first sub-association is 0 in all other assignment scenarios.
[0103] The first sub-association scores corresponding to all test coverage paths in the target test case are summarized to obtain the first association score corresponding to any fault coverage path.
[0104] The target association score is obtained by combining the first association scores corresponding to all the fault coverage paths.
[0105] For each fault coverage path, the first sub-association score can be determined based on different combinations of node position assignments and test coverage path node position assignments.
[0106] Specifically, if a node in the fault coverage path is assigned a value of 1, and a node in the test coverage path is assigned a value of 1 or 3, it indicates that the test coverage path is related to the fault coverage path at that node, and the first sub-association score for the test coverage path is recorded as 1. If a node in the fault coverage path is assigned a value of 2, and a node in the test coverage path is assigned a value of 1 or 3, it indicates that the association between the test coverage path and the fault coverage path is even stronger at that point, and the first sub-association score is recorded as 2. In all other cases besides these two assignment scenarios, the first sub-association score is recorded as 0.
[0107] After calculating the first sub-association score for each test coverage path, the first sub-association scores for all test coverage paths in the target test case can be summarized to obtain the first association score for that fault coverage path.
[0108] Finally, the initial correlation scores corresponding to all fault coverage paths are comprehensively considered to arrive at the target correlation score. This target correlation score reflects the overall correlation between the target test case and the fault coverage path, providing an important basis for prioritizing subsequent test cases.
[0109] like Figure 2 The diagram shown is a system block diagram of a path-based test case priority sequence recommendation system provided in an embodiment of the present invention. The recommendation system includes:
[0110] The information acquisition module is used to acquire test execution information of the target test cases based on the new version of the program and the old version of the program;
[0111] The position assignment module is used to assign values to the positions of each node in the test coverage path of the target test case based on the test execution information, and generate a test path feature vector.
[0112] The model training module is used to train a fault prediction model based on the XGBoost algorithm, with the feature vector of the test path and the program execution result in the target test case as input and output, respectively.
[0113] The fault prediction module is used to determine the predicted fault probability of the basic coverage path in the new version of the program based on the fault prediction model, and to filter out the fault coverage path based on the predicted fault probability.
[0114] The sequence generation module is used to calculate the target association score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, and arrange the target test cases from largest to smallest according to the target association score to generate a priority recommendation sequence.
[0115] Figure 2 The apparatus of the illustrated embodiment can be used to perform corresponding actions. Figure 1 The steps in the method embodiments shown are implemented in a similar manner and have similar technical effects, and will not be repeated here.
[0116] An electronic device includes a memory and a processor, wherein the memory stores a computer program, and when the processor runs the computer program stored in the memory, the processor performs the steps of a path-based test case priority sequence recommendation method as described in any of the preceding claims.
[0117] like Figure 3 The diagram shown is a hardware structure schematic of an electronic device according to an embodiment of the present invention. The electronic device 30 includes: a processor 31, a memory 32, and a computer program; wherein...
[0118] The memory 32 is used to store the computer program, and the memory may also be flash memory. The computer program is, for example, an application program or functional module that implements the above method.
[0119] Processor 31 is configured to execute the computer program stored in the memory to implement the various steps performed by the device in the above method. For details, please refer to the relevant descriptions in the preceding method embodiments.
[0120] Alternatively, the memory 32 can be either standalone or integrated with the processor 31.
[0121] When the memory 32 is a device independent of the processor 31, the device may further include:
[0122] Bus 33 is used to connect the memory 32 and the processor 31.
[0123] A readable storage medium storing a computer program, which, when executed by a processor, is used to implement the steps of a path-based test case priority sequence recommendation method as described in any of the preceding claims.
[0124] The readable storage medium can be a computer storage medium or a communication medium. A communication medium includes any medium that facilitates the transfer of computer programs from one location to another. A computer storage medium can be any available medium accessible to a general-purpose or special-purpose computer. For example, a readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application-Specific Integrated Circuit (ASIC). Alternatively, the ASIC can be located in a user equipment. Of course, the processor and the readable storage medium can also exist as discrete components in a communication device. The readable storage medium can be a read-only memory (ROM), random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0125] The present invention also provides a program product including executable instructions stored in a readable storage medium. At least one processor of the device can read the executable instructions from the readable storage medium, and the at least one processor executes the executable instructions to cause the device to implement the methods provided in the various embodiments described above.
[0126] In the embodiments of the above-described device, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0127] Through the above embodiments, this invention, through a path-based test case priority sequence recommendation method and system, can obtain test execution information of target test cases based on both new and old versions of the program; based on the test execution information, assign values to the node positions of the test coverage paths in the target test cases to generate test path feature vectors; based on the XGBoost algorithm, train a fault prediction model using the test path feature vectors and the program execution results in the target test cases as input and output, respectively; based on the fault prediction model, determine the predicted fault probability of the basic coverage paths in the new version of the program, and filter out fault coverage paths based on the predicted fault probabilities; based on preset recommendation rules, calculate the target association score between the test coverage paths and fault coverage paths in each target test case, and arrange the target test cases according to the target association score from largest to smallest to generate a priority recommendation sequence, thereby effectively covering fault paths and improving the accuracy of test case priority ranking.
[0128] This invention compares the control flow graphs of old and new program versions, marks node changes, generates test path feature vectors, and uses the XGBoost algorithm to train a fault prediction model. This allows for accurate prediction of the fault probability of basic coverage paths in the new program version, thus identifying faulty coverage paths. Based on this, by calculating the target association score between test coverage paths and faulty coverage paths, a reasonable prioritization of test cases is achieved. This method fully considers program path changes and fault associations, improves the accuracy of test case prioritization, effectively covers potentially faulty paths, and enhances testing efficiency and quality.
[0129] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A path-based test case priority sequence recommendation method, characterized in that, The recommendation method includes: Obtain test execution information for the target test cases based on both the new and old versions of the program; After obtaining the test execution information, compare the control flow graphs of the new version program and the old version program; Based on the edit distance algorithm, the edit distance between each node in the control flow graph of the new version program and the old version program is calculated; If the edit distance is 0, then the node is marked as an unchanged node; If the edit distance is not 0, and the node only exists in the new version of the program, then the node is marked as a new node; If the edit distance is not 0, and the node only exists in the old version of the program, then the node is marked as a deleted node; Based on the test execution information, values are assigned to the positions of each node in the test coverage path of the target test case to generate a test path feature vector; Based on the test execution information, the longest path length in the test coverage path is obtained as the dimension of the test path feature vector. Then, the value at the unchanged node position is 1; the value at the newly added node position is 3; the value at the deleted node position is 2; and the value at the remaining node positions in the test coverage path is 0. Based on the values assigned at the positions of the unchanged nodes, the newly added nodes, the deleted nodes, and the remaining nodes, the test path feature vector is generated. Based on the XGBoost algorithm, a fault prediction model is trained using the feature vector of the test path and the program execution result in the target test case as input and output, respectively. Based on the fault prediction model, the predicted fault probability of the basic coverage path in the new version of the program is determined, and the fault coverage path is obtained by filtering based on the predicted fault probability. Based on preset recommendation rules, the target association score between the test coverage path and the fault coverage path in each target test case is calculated. The target test cases are then arranged in descending order of the target association score to generate a priority recommendation sequence.
2. The path-based test case priority sequence recommendation method according to claim 1, characterized in that, Before training the fault prediction model with the test path feature vector and the program execution result in the target test case as input and output respectively based on the XGBoost algorithm, the principal component analysis technique is used to perform dimensionality reduction on the test path feature vector That is, the test path feature vector is reduced from dimension D to dimension D', where D' < D. Specifically, it includes: For the test path feature vector Standardize the process until all the test path feature vectors are defined. The mean is 0 and the variance is 1. Calculate the feature vector of the test path The corresponding covariance matrix C; Solve for the eigenvalues and eigenvectors of the covariance matrix C; Arrange all the matrix eigenvalues from largest to smallest, select the matrix eigenvectors corresponding to the first D' matrix eigenvalues, and form a projection matrix W; The test path feature vector Projecting the vectors onto the projection matrix W yields the dimensionality-reduced test path feature vectors. And the dimensionality-reduced test path feature vector The dimension is D'.
3. The path-based test case priority sequence recommendation method according to claim 1, characterized in that, The process of determining the predicted fault probability of the basic coverage path in the new version of the program based on the fault prediction model, and filtering out fault coverage paths based on the predicted fault probability, specifically includes: The McCabe cyclic complexity algorithm is used to extract the basic coverage path in the new version of the program. The positions of each node in the basic coverage path are assigned values to generate a basic path feature vector, which is then input into the fault prediction model. Based on the fault prediction model, the sigmoid function is used to transform the basic path feature vector into the predicted fault probability. A preset fault path ratio of Y% is obtained. All predicted fault probabilities are sorted from largest to smallest, and the basic coverage paths corresponding to the top Y% of predicted fault probabilities are selected as the fault coverage paths.
4. A path-based test case priority sequence recommendation system, applied to the path-based test case priority sequence recommendation method as described in any one of claims 1-3, characterized in that, The recommendation system includes: The information acquisition module is used to acquire test execution information of the target test cases based on the new version of the program and the old version of the program; After obtaining the test execution information, compare the control flow graphs of the new version program and the old version program; Based on the edit distance algorithm, the edit distance between each node in the control flow graph of the new version program and the old version program is calculated; If the edit distance is 0, then the node is marked as an unchanged node; If the edit distance is not 0, and the node only exists in the new version of the program, then the node is marked as a new node; If the edit distance is not 0, and the node only exists in the old version of the program, then the node is marked as a deleted node; The position assignment module is used to assign values to the positions of each node in the test coverage path of the target test case based on the test execution information, and generate a test path feature vector. Based on the test execution information, the longest path length in the test coverage path is obtained as the dimension of the test path feature vector. Then, the value at the unchanged node position is 1; the value at the newly added node position is 3; the value at the deleted node position is 2; and the value at the remaining node positions in the test coverage path is 0. Based on the values assigned at the positions of the unchanged nodes, the newly added nodes, the deleted nodes, and the remaining nodes, the test path feature vector is generated. The model training module is used to train a fault prediction model based on the XGBoost algorithm, with the feature vector of the test path and the program execution result in the target test case as input and output, respectively. The fault prediction module is used to determine the predicted fault probability of the basic coverage path in the new version of the program based on the fault prediction model, and to filter out the fault coverage path based on the predicted fault probability. The sequence generation module is used to calculate the target association score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, and arrange the target test cases in descending order of the target association score to generate a priority recommendation sequence.
5. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor runs the computer program stored in the memory, the processor performs the steps of a path-based test case priority sequence recommendation method as described in any one of claims 1-3.
6. A readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it is used to implement the steps of a path-based test case priority sequence recommendation method as described in any one of claims 1-3.
Citation Information
Patent Citations
Test case precise recommendation method, device and system, equipment and storage medium
CN107515826A
Regression test case determination method and device, storage medium and electronic equipment
CN119473916A