Path-based test case priority sequence recommendation method and system

By generating test path feature vectors and using XGBoost algorithm to train the fault prediction model, the problem of inaccurate priority sorting of test cases in traditional methods is solved, and the accurate coverage of fault paths in the new version of the program is achieved, which improves the testing efficiency and quality.

CN120448267AActive Publication Date: 2025-08-08QINGDAO UNIV OF SCI & TECH

Patent Information

Application Number
CN202510534896.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2025-08-08
Estimated Expiration
2045-04-27

AI Technical Summary

Technical Problem

The traditional test case priority determination method cannot fully consider the path changes before and after the program version update and the association between paths and failures, resulting in the test case priority sorting inaccurate enough and cannot effectively cover paths that may have faults, affecting the test effect.

Method used

The path-based test case priority sequence recommendation method is used to obtain test execution information of new and old versions of the program, generate test path feature vectors, and use XGBoost algorithm to train the fault prediction model, determine the predicted failure probability of the basic coverage path in the new version of the program, and calculate the correlation score between the test coverage path and the fault coverage path, and generate a priority recommendation sequence.

Benefits of technology

It improves the accuracy of priority sorting of test cases, can effectively cover fault paths, improves test efficiency and quality, and fully considers program path changes and fault association relationships.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448267A_ABST
    Figure CN120448267A_ABST
Patent Text Reader

Abstract

The invention provides a path-based test case priority sequence recommendation method and system, and relates to the technical field of software testing, and the method comprises the following steps: obtaining test execution information of a target test case based on new and old version programs; assigning each node position of a test coverage path in the target test case to generate a test path feature vector; based on an XGBoost algorithm, respectively taking the test path feature vector and the program execution result as input and output, and training a fault prediction model; based on the fault prediction model, determining a prediction fault probability of a basic coverage path in the new version program, and screening to obtain a fault coverage path; according to the method, the target association scores of the test coverage paths and the fault coverage paths in the target test cases are calculated based on the preset recommendation rule, the target test cases are arranged according to the target association scores from large to small, and the priority recommendation sequence is generated, so that the fault paths can be effectively covered, and the accuracy of priority ranking of the test cases can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software testing, and in particular to a path-based test case priority sequence recommendation method and system. Background Art

[0002] In the field of software testing, with the continuous updating of software versions, how to efficiently determine the priority of test cases and improve testing efficiency and quality is an important technical issue currently faced.

[0003] Traditional test case prioritization methods often fail to fully consider path changes before and after program version updates and the correlation between paths and faults. As a result, the test case prioritization is inaccurate and cannot effectively cover paths that may have faults, seriously affecting the test results.

[0004] Therefore, it is necessary to provide a path-based test case priority sequence recommendation method and system to solve the above technical problems. Summary of the Invention

[0005] In order to solve the above technical problems, the present invention provides a path-based test case priority sequence recommendation method and system, which are used to solve the problem that the traditional test case priority sequence recommendation method cannot effectively cover the fault path and is not accurate enough.

[0006] The present invention provides a path-based test case priority sequence recommendation method, the recommendation method comprising:

[0007] Obtain test execution information of the target test case based on the new version program and the old version program;

[0008] Based on the test execution information, assigning a value to each node position of the test coverage path in the target test case to generate a test path feature vector;

[0009] Based on the XGBoost algorithm, the fault prediction model is trained with the test path feature vector and the program execution result in the target test case as input and output respectively;

[0010] Determine the predicted failure probability of the basic coverage path in the new version of the program based on the fault prediction model, and select the fault coverage path based on the predicted failure probability;

[0011] Based on preset recommendation rules, the target correlation scores of the test coverage paths and the fault coverage paths in each target test case are calculated, and the target test cases are arranged from large to small according to the target correlation scores 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, assign 1 to the position of the unchanged node; assign 3 to the position of the added node; assign 2 to the position of the deleted node; and assign 0 to the positions of the remaining nodes in the test coverage path;

[0018] Generate the test path feature vector based on the assignments at the positions of the unchanged nodes, the added nodes, the deleted nodes, and the remaining nodes.

[0019] Preferably, before training a fault prediction model using the XGBoost algorithm with the test path feature vector and the program execution results in the target test cases as input and output respectively, use the principal component analysis technique to reduce the dimension of 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] Normalize 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, select the matrix eigenvectors corresponding to the first D′ matrix eigenvalues, and form a projection matrix W;

[0024] The test path feature vector Projected onto the projection matrix W, the test path feature vector after dimensionality reduction is obtained And the test path feature vector after dimensionality reduction The dimension is D′.

[0025] Preferably, determining the predicted failure probability of the basic coverage path in the new version of the program based on the fault prediction model, and screening to obtain the fault coverage path based on the predicted failure probability, specifically includes:

[0026] Using McCabe's cyclomatic complexity algorithm to extract the basic coverage path in the new version program;

[0027] Assigning a value to each node position of the basic coverage path, generating a basic path feature vector and inputting the feature vector into the fault prediction model;

[0028] Based on the fault prediction model, using a sigmoid function to convert the basic path feature vector into the predicted fault probability;

[0029] A preset fault path ratio of Y% is obtained, all the predicted fault probabilities are arranged from large to small, and the basic coverage paths corresponding to the predicted fault probabilities of the first Y% are screened as the fault coverage paths.

[0030] Preferably, the calculating of the target correlation score between the test coverage path and the fault coverage path in each target test case based on a preset recommendation rule specifically includes:

[0031] For any of the fault coverage paths, if the value assigned at any node position in the fault coverage path is 1, and the value assigned 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 at any node position in the fault coverage path is 2, and the value assigned 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 2;

[0033] Except for the above two assignment cases, the first sub-association score in other assignment cases is 0.

[0034] Preferably, the first sub-correlation scores corresponding to all the test coverage paths in the target test case are aggregated to obtain the first correlation score corresponding to any of the fault coverage paths;

[0035] The target correlation score is obtained by combining the first correlation scores corresponding to all the fault coverage paths.

[0036] A path-based test case priority sequence recommendation system, the recommendation system comprising:

[0037] An information acquisition module is used to obtain test execution information of a target test case based on a new version of the program and an old version of the program;

[0038] A position assignment module, configured to assign a value to each node position of the test coverage path in the target test case based on the test execution information, and generate a test path feature vector;

[0039] A model training module is used to train a fault prediction model based on an XGBoost algorithm, taking the test path feature vector and the program execution result in the target test case as input and output respectively;

[0040] A 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 screen and obtain the fault coverage path based on the predicted fault probability;

[0041] A sequence generation module is used to calculate the target correlation score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, arrange the target test cases from large to small according to the target correlation score, and generate a priority recommendation sequence.

[0042] An electronic device includes a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes the steps of a path-based test case priority sequence recommendation method as described in any one of the above items.

[0043] A readable storage medium stores 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 one of the above.

[0044] Compared with related technologies, the path-based test case priority sequence recommendation method and system provided by the present invention have the following beneficial effects:

[0045] The present invention can obtain the test execution information of the target test case based on the new version program and the old version program; based on the test execution information, assign a value to the position of each node of the test coverage path in the target test case to generate a test path feature vector; based on the XGBoost algorithm, the test path feature vector and the program execution result in the target test case are used as input and output respectively to train a fault prediction model; based on the fault prediction model, the predicted fault probability of the basic coverage path in the new version program is determined, and the fault coverage path is obtained by screening based on the predicted fault probability; based on the preset recommendation rules, the target correlation score of the test coverage path and the fault coverage path in each target test case is calculated, the target test cases are arranged from large to small according to the target correlation score, and a priority recommendation sequence is generated, so that the fault path can be effectively covered and the accuracy of the test case priority sorting can be improved.

[0046] The present invention compares the control flow graphs of the new and old versions of the program, marks the node changes, generates a test path feature vector, and uses the XGBoost algorithm to train a fault prediction model, thereby accurately predicting the failure probability of the basic coverage path in the new version of the program and screening out the fault coverage path. On this basis, by calculating the target correlation score of the test coverage path and the fault coverage path, a reasonable sorting of test case priorities is achieved. This method fully considers the relationship between program path changes and fault associations, improves the accuracy of test case priority sorting, can effectively cover paths that may have faults, and improves test efficiency and quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A flowchart of a path-based test case priority sequence recommendation method provided by an embodiment of the present invention;

[0048] Figure 2 A system block diagram of a path-based test case priority sequence recommendation system provided by an embodiment of the present invention;

[0049] Figure 3 A schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0051] like Figure 1FIG. 1 is a flow chart of a path-based test case priority sequence recommendation method provided by an embodiment of the present invention. Figure 1 The execution subject of the method shown may be a software and / or hardware device. The execution subject of the present application may include but is not limited to at least one of the following: user equipment, network equipment, etc. Among them, the user equipment may include but is not limited to computers, smart phones, personal digital assistants (PDAs) and the electronic devices mentioned above. Network equipment may 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, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computers. This embodiment does not limit this. It includes steps S1 to S5, as follows:

[0052] S1, obtain the test execution information of the target test case based on the new version program and the old version program;

[0053] In software testing scenarios, target test cases refer to pre-designed combinations of specific inputs and expected outputs, which are used to verify the compliance of program functions.

[0054] By deploying the target test cases in the new and old versions of the program for execution, we can collect the response data of the two types of programs to the same test cases, namely the test execution information, which specifically includes dynamic operation characteristics such as program control flow trajectory, node execution status, output result correctness, exception throwing records, etc.

[0055] S2, assigning a value to each node position of the test coverage path in the target test case based on the test execution information to generate a test path feature vector;

[0056] It can be understood that by assigning values to the positions of each node in the test coverage path within the target test case based on the test execution information, the test path information can be converted into a feature vector that can be processed by the machine learning algorithm. Furthermore, the node position assignment is based on the changes in the node in the program control flow graph.

[0057] During the software version update process, nodes in the program control flow graph may remain unchanged, be added, or be deleted. In order to accurately reflect these changes, different values can be assigned to different types of nodes. Specifically, the value assigned to the unchanged node position is 1, which means that the node remains unchanged in the old and new versions of the program and is a relatively stable part of the program; the value assigned to the newly added node position is 3, because the newly added node represents the new logic or function in the new version of the program and may be a potential area for failure; the value assigned to the deleted node position is 2, indicating that the node existed in the old version but has been deleted in the new version. This change may also affect the overall function of the program; and the remaining nodes in the test coverage path are assigned a value of 0. These nodes may not be closely related to the focus of this test.

[0058] Based on the node assignments above, a test path feature vector can be generated. This feature vector mathematically represents the test path information, facilitating subsequent processing by machine learning algorithms. The dimension of the test path feature vector is typically determined by the longest path length among the test coverage paths. It comprehensively describes the test path structure and node changes.

[0059] S3, based on the XGBoost algorithm, using the test path feature vector and the program execution result in the target test case as input and output respectively, training a fault prediction model;

[0060] It's important to note 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, and its ability to handle large datasets and complex feature relationships, this algorithm was used to train the fault prediction model in this method.

[0061] Furthermore, a fault prediction model is trained using the test path feature vector as input and the program execution results in the target test case as output. Program execution results can be categorized as either failures or no failures. Using a large amount of training data, the fault prediction model learns the relationship between test path features and fault occurrence. Furthermore, during training, the model continuously adjusts its parameters to minimize the error between predicted and actual results.

[0062] S4, determining the predicted failure probability of the basic coverage path in the new version of the program based on the fault prediction model, and screening the fault coverage path based on the predicted failure probability;

[0063] The basic coverage path is a simplified representation of all possible execution paths in a program, extracted using the McCabe Cyclomatic Complexity Algorithm. The basic coverage path is then converted into a basic path feature vector and input into the fault prediction model. Based on the previously learned relationship between features and faults, the model 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 execution of that path.

[0064] To concentrate testing resources and improve test efficiency, it's necessary to screen fault coverage paths based on predicted failure probabilities. With a default failure path ratio of Y%, all basic coverage paths are ranked from highest to lowest by predicted failure probability. The top Y% of basic coverage paths are selected as the fault coverage paths. These paths are the most likely to fail, and focusing testing on them can more effectively identify software issues.

[0065] S5. Based on preset recommendation rules, calculate the target correlation score between the test coverage path and the fault coverage path in each target test case, arrange the target test cases from large to small according to the target correlation score, and generate a priority recommendation sequence.

[0066] It's understandable that the target relevance score reflects the degree of test case coverage of potentially faulty paths. The first sub-relevance score is determined based on the assignment of node positions within the fault coverage path and the test coverage path. Then, by summing the first sub-relevance scores for all test coverage paths, we can obtain the first relevance score for any fault coverage path. Finally, we combine the first relevance scores for all fault coverage paths to arrive at the target relevance score.

[0067] Furthermore, target test cases can be ranked from highest to lowest according to their target relevance scores to generate a priority recommendation sequence. Test cases with higher target relevance scores demonstrate better coverage of fault coverage paths and are more likely to discover software faults, thus being prioritized. This prioritization allows testers to focus limited testing resources on the test cases most likely to discover problems, improving testing relevance and efficiency.

[0068] By comparing the new and old versions of the program, extracting test path features, training a fault prediction model, screening fault coverage paths, and calculating correlation scores to generate a priority sequence, this approach fully accounts for path changes and the likelihood of faults during program version updates. This allows for a more scientific arrangement of test case execution, thereby improving software testing efficiency and quality and reducing the risk of post-release failures. In practical applications, parameters such as the preset fault path ratio (Y%) can be adjusted to achieve optimal testing results based on the characteristics of different software projects and testing requirements.

[0069] In a 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] Calculating the edit distance between nodes in the control flow graph of the new version program and the old version program based on an edit distance algorithm;

[0071] If the edit distance is 0, mark the node as unchanged;

[0072] If the edit distance is not 0, and the node only exists in the new version of the program, marking the node as a newly added node;

[0073] If the edit distance is not 0, and the node only exists in the old version of the program, 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 of the program execution process. By comparing control flow graphs, we can clearly understand the structural and logical changes between program versions.

[0075] To accurately identify changes to nodes in the control flow graph, we can use the edit distance algorithm to calculate the minimum number of operations required to convert two strings through operations such as insertion, deletion, and replacement. In this scenario, we use it to calculate the edit distance between each node in the control flow graph of the new version of the program and the old version of the program.

[0076] Then, the nodes can be labeled and classified based on the calculated edit distance. If the edit distance is 0, it means that 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 means that this node is newly added in the new version, and it will be marked as a newly added 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 means that this node has been deleted in the new version, and it will be marked as a deleted node. This marking 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, and the value assigned to the unchanged node position is 1; the value assigned to the newly added node position is 3; the value assigned to the deleted node position is 2; and the value assigned to the remaining node positions of 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 test coverage paths, a test path feature vector needs to be constructed. First, based on the test execution information, the longest path length 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 fully captures information about all test coverage paths.

[0080] Next, you can assign values based on the different node types. Unchanged nodes, since they remain stable between the old and new versions of the program, are assigned a value of 1. Newly added nodes represent new logic or functionality in the new version of the program and are potential areas of high failure risk, so they are assigned a value of 3. Deleted nodes, which have been removed from the new version and whose changes may affect the overall functionality of the program, are assigned a value of 2. The remaining nodes in the test coverage path are less relevant to the current test focus and are assigned a value of 0.

[0081] Finally, we can generate a test path feature vector based on the values assigned to unchanged, newly added, deleted, and remaining nodes. This vector mathematically accurately describes the structure of the test coverage path and node changes, providing critical data support for subsequent analysis such as fault prediction using machine learning algorithms.

[0082] Based on the XGBoost algorithm, the test path feature vector and the program execution result in the target test case are used as input and output respectively, and the principal component analysis technology is used to train the fault prediction model before the fault prediction model is trained. 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 top 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 a 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. Select the matrix eigenvectors corresponding to the top D' matrix eigenvalues to form a projection matrix. Finally, project the test path feature vector onto the projection matrix to obtain a 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 for 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, using a sigmoid function to convert the basic path feature vector into the predicted fault probability;

[0094] A preset fault path ratio of Y% is obtained, all the predicted fault probabilities are arranged from large to small, and the basic coverage paths corresponding to the predicted fault probabilities of the first Y% are screened as the fault coverage paths.

[0095] The McCabe Cyclomatic Complexity Algorithm can be used to extract the basic coverage paths in the new version of the program. This algorithm can analyze the control structure of the program and identify all possible independent execution paths in the program, which constitute the basic coverage path set.

[0096] Next, we can assign values to each node in the basic coverage path. Based on the node's characteristics in the program, we assign different values to generate a basic path feature vector. This feature vector can fully and accurately describe the characteristics of the basic coverage path.

[0097] The basic path feature vector can then be input into the fault prediction model and converted into a predicted fault probability using the sigmoid function. The sigmoid function maps the model's output to a range between 0 and 1, with the value within this range representing the probability of a fault on the basic coverage path.

[0098] Finally, we can obtain a pre-set fault path percentage (Y%). We then sort the predicted fault probabilities of all basic coverage paths from highest to lowest, and select the top Y% of basic coverage paths as the fault coverage paths. We can then focus on testing these fault coverage paths, effectively discovering potential faults in the software and improving testing efficiency and software quality.

[0099] The calculating, based on the preset recommendation rule, the target correlation score between the test coverage path and the fault coverage path in each target test case specifically includes:

[0100] For any of the fault coverage paths, if the value assigned at any node position in the fault coverage path is 1, and the value assigned 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 at any node position in the fault coverage path is 2, and the value assigned 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 2;

[0102] Except for the above two assignment cases, the first sub-association score in other assignment cases is 0.

[0103] Aggregating the first sub-correlation scores corresponding to all the test coverage paths in the target test case to obtain the first correlation score corresponding to any of the fault coverage paths;

[0104] The target correlation score is obtained by combining the first correlation scores corresponding to all the fault coverage paths.

[0105] For each fault coverage path, a first sub-association score may be determined according to different combinations of its node position assignments and the test coverage path node position assignments.

[0106] Specifically, if a node position in the fault coverage path is assigned a value of 1, and a node position in the test coverage path is assigned a value of 1 or 3, it indicates that the test coverage path has a certain correlation with the fault coverage path at that node, and the first sub-correlation score corresponding to the test coverage path is recorded as 1. If a node position in the fault coverage path is assigned a value of 2, and a node position in the test coverage path is assigned a value of 1 or 3, it indicates that the test coverage path and the fault coverage path are more closely correlated at this location, and the first sub-correlation score is recorded as 2. In all other cases except the above two assignment cases, the first sub-correlation score is recorded as 0.

[0107] After calculating the first sub-correlation score corresponding to each test coverage path, the first sub-correlation scores corresponding to all test coverage paths in the target test case may be aggregated to obtain the first correlation score corresponding to the fault coverage path.

[0108] Finally, the first correlation scores corresponding to all fault coverage paths can be comprehensively considered to obtain the target correlation score. This target correlation score can reflect the overall correlation between the target test case and the fault coverage path, providing an important basis for the prioritization of subsequent test cases.

[0109] like Figure 2 FIG. 1 is a system block diagram of a path-based test case priority sequence recommendation system provided by an embodiment of the present invention. The recommendation system includes:

[0110] An information acquisition module is used to obtain test execution information of a target test case based on a new version of the program and an old version of the program;

[0111] A position assignment module, configured to assign a value to each node position of the test coverage path in the target test case based on the test execution information, and generate a test path feature vector;

[0112] A model training module is used to train a fault prediction model based on an XGBoost algorithm, taking the test path feature vector and the program execution result in the target test case as input and output respectively;

[0113] A 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 screen and obtain the fault coverage path based on the predicted fault probability;

[0114] A sequence generation module is used to calculate the target correlation score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, arrange the target test cases from large to small according to the target correlation score, and generate a priority recommendation sequence.

[0115] Figure 2 The apparatus of the embodiment shown can be used to perform Figure 1 The implementation principles and technical effects of the steps in the method embodiment shown are similar and will not be repeated here.

[0116] An electronic device includes a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes the steps of a path-based test case priority sequence recommendation method as described in any one of the above items.

[0117] like Figure 3 FIG. 1 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. The electronic device 30 includes: a processor 31, a memory 32 and a computer program;

[0118] The memory 32 is used to store the computer program, which may also be a flash memory. The computer program is, for example, an application program or a functional module for implementing the above method.

[0119] The 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 description in the above method embodiment.

[0120] Optionally, the memory 32 may be independent 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] The bus 33 is used to connect the memory 32 and the processor 31 .

[0123] A readable storage medium stores 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 one of the above.

[0124] Among them, the readable storage medium can be a computer storage medium or a communication medium. Communication media include any medium that facilitates the transmission of computer programs from one place to another. Computer storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer. For example, a readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application-specific integrated circuit (ASIC). In addition, the ASIC can be located in a user device. Of course, the processor and the readable storage medium can also exist in a communication device as discrete components. The readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0125] The present invention also provides a program product, which includes execution instructions stored in a readable storage medium. At least one processor of a device can read the execution instructions from the readable storage medium, and at least one processor executes the execution instructions so that the device implements the methods provided in the various embodiments described above.

[0126] In the embodiments of the above-mentioned devices, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the present invention may be directly implemented by a hardware processor or implemented by a combination of hardware and software modules in the processor.

[0127] Through the introduction of the above embodiments, the present invention can obtain the test execution information of the target test case based on the new version program and the old version program through the path-based test case priority sequence recommendation method and system; based on the test execution information, assign a value to each node position of the test coverage path in the target test case to generate a test path feature vector; based on the XGBoost algorithm, the fault prediction model is trained with the test path feature vector 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 program is determined, and the fault coverage path is obtained based on the predicted fault probability; based on the preset recommendation rules, the target correlation score of the test coverage path and the fault coverage path in each target test case is calculated, and the target test cases are arranged from large to small according to the target correlation score to generate a priority recommendation sequence, so as to effectively cover the fault path and improve the accuracy of the test case priority sorting.

[0128] The present invention compares the control flow graphs of the new and old versions of the program, marks the node changes, generates a test path feature vector, and uses the XGBoost algorithm to train a fault prediction model, thereby accurately predicting the failure probability of the basic coverage path in the new version of the program and screening out the fault coverage path. On this basis, by calculating the target correlation score of the test coverage path and the fault coverage path, a reasonable sorting of test case priorities is achieved. This method fully considers the relationship between program path changes and fault associations, improves the accuracy of test case priority sorting, can effectively cover paths that may have faults, and improves test 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, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements 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 recommended methods include: Obtain test execution information of the target test case based on the new version program and the old version program; Based on the test execution information, assigning a value to each node position of the test coverage path in the target test case to generate a test path feature vector; Based on the XGBoost algorithm, the fault prediction model is trained with the test path feature vector and the program execution result in the target test case as input and output respectively; Determine the predicted failure probability of the basic coverage path in the new version of the program based on the fault prediction model, and select the fault coverage path based on the predicted failure probability; Based on preset recommendation rules, the target correlation scores of the test coverage paths and the fault coverage paths in each target test case are calculated, and the target test cases are arranged from large to small according to the target correlation scores to generate a priority recommendation sequence.

2. A path-based test case priority sequence recommendation method according to claim 1, characterized in that: After obtaining the test execution information, comparing the control flow graphs of the new version program and the old version program; Calculating the edit distance between nodes in the control flow graph of the new version program and the old version program based on an edit distance algorithm; If the edit distance is 0, mark the node as unchanged; If the edit distance is not 0, and the node only exists in the new version of the program, marking the node as a newly added node; If the edit distance is not 0, and the node only exists in the old version of the program, the node is marked as a deleted node.

3. A path-based test case priority sequence recommendation method according to claim 2, characterized in that: 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, and the value assigned to the unchanged node position is 1; the value assigned to the newly added node position is 3; and the value assigned to the deleted node position is 2; The values assigned to the remaining node positions of the test coverage path are 0; 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.

4. A 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: The test path feature vector Perform normalization until all the test path feature vectors The mean of is 0 and the variance is 1; Calculate the test path feature vector The corresponding covariance matrix C; Solving the matrix eigenvalues and matrix eigenvectors of the covariance matrix C; Arrange all the matrix eigenvalues from large to small, select the matrix eigenvectors corresponding to the first D' matrix eigenvalues, and form a projection matrix W; The test path feature vector Projected onto the projection matrix W, the test path feature vector after dimensionality reduction is obtained And the test path feature vector after dimensionality reduction The dimension is D′.

5. The path-based test case priority sequence recommendation method according to claim 1, characterized in that: The step of determining the predicted failure probability of the basic coverage path in the new version of the program based on the fault prediction model, and selecting the fault coverage path based on the predicted failure probability, specifically includes: Using McCabe's cyclomatic complexity algorithm to extract the basic coverage path in the new version program; Assigning a value to each node position of the basic coverage path, generating a basic path feature vector and inputting the feature vector into the fault prediction model; Based on the fault prediction model, using a sigmoid function to convert the basic path feature vector into the predicted fault probability; A preset fault path ratio of Y% is obtained, all the predicted fault probabilities are arranged from large to small, and the basic coverage paths corresponding to the predicted fault probabilities of the first Y% are screened as the fault coverage paths.

6. A path-based test case priority sequence recommendation method according to claim 1, characterized in that: The calculating, based on the preset recommendation rule, the target correlation score between the test coverage path and the fault coverage path in each target test case specifically includes: For any of the fault coverage paths, if the value assigned at any node position in the fault coverage path is 1, and the value assigned 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; If the value assigned at any node position in the fault coverage path is 2, and the value assigned 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 2; Except for the above two assignment cases, the first sub-association score in other assignment cases is 0.

7. A path-based test case priority sequence recommendation method according to claim 6, characterized in that: Aggregating the first sub-correlation scores corresponding to all the test coverage paths in the target test case to obtain the first correlation score corresponding to any of the fault coverage paths; The target correlation score is obtained by combining the first correlation scores corresponding to all the fault coverage paths.

8. A path-based test case priority sequence recommendation system, applied to a path-based test case priority sequence recommendation method according to any one of claims 1 to 7, characterized in that: The recommendation system includes: An information acquisition module is used to obtain test execution information of a target test case based on a new version of the program and an old version of the program; A position assignment module, configured to assign a value to each node position of the test coverage path in the target test case based on the test execution information, and generate a test path feature vector; A model training module is used to train a fault prediction model based on an XGBoost algorithm, taking the test path feature vector and the program execution result in the target test case as input and output respectively; A 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 screen and obtain the fault coverage path based on the predicted fault probability; A sequence generation module is used to calculate the target correlation score between the test coverage path and the fault coverage path in each target test case based on preset recommendation rules, arrange the target test cases from large to small according to the target correlation score, and generate a priority recommendation sequence.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor runs the computer program stored in the memory, the processor executes the steps of the path-based test case priority sequence recommendation method according to any one of claims 1 to 7.

10. A readable storage medium storing a computer program, wherein: 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 to 7.

Citation Information

Patent Citations

  • Regression-testing-oriented control flow change influence domain analyzing method and system

    CN104834603A

  • Test case precise recommendation method, device and system, equipment and storage medium

    CN107515826A

  • Test method and system for sequencing test case priorities by using ensemble learning

    CN111427802A

  • Test case selection method and device applied to distributed storage system and medium

    CN114327594A

  • Test case sorting model training method and device, electronic equipment and storage medium

    CN116932398A

Cited By

  • Method and system for automatically testing software

    CN121579360A