Large-scale complex software system test case recommendation method based on deep reinforcement learning
By constructing multi-level correlation features between test cases and code through deep reinforcement learning, the problem of dynamic changes in test case recommendations in large-scale complex software systems is solved, thereby improving testing efficiency and resource utilization.
Patent Information
- Application Number
- CN202511636376.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-03-24
AI Technical Summary
Existing software test case recommendation methods struggle to handle dynamic changes and uncertainties in large-scale, complex software systems. They lack multi-dimensional analysis of the test environment, cannot respond promptly to code changes, and lack long-term optimization capabilities, resulting in limited improvements in test efficiency.
We employ a deep reinforcement learning-based approach to construct multi-layered test case and code association features, establishing the essential relationship between test cases and code changes and defect patterns. We comprehensively consider the complementarity and redundancy between test cases and dynamically adjust the recommendation strategy through multi-loop adaptive training to form environment-adaptive test case recommendations.
It enables smarter and more efficient test case recommendations, significantly improving the defect detection efficiency and test resource utilization in continuous integration environments.
Smart Images

Figure CN121722663A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of software test case recommendation, and in particular to a large-scale complex software system test case recommendation method based on deep reinforcement learning. BACKGROUND
[0002] With the continuous expansion of the scale of software systems and the increasing complexity of functions, the necessity of software testing is increasingly prominent. As a verification means, software testing exposes potential defects in software through test cases to ensure the effectiveness of software functions and system stability. Among them, regression testing plays an important role in the version update process of large-scale complex software systems, and is specifically used to verify that code updates will not cause degradation of existing functions.
[0003] In order to optimize the allocation of test resources and maximize the defect detection effect that test cases can achieve, the use of test case recommendation technology has become an important practice in modern software testing. Software test case recommendation aims to filter out high-value and high-priority test cases from a large number of test cases through traditional or intelligent techniques, thereby improving test efficiency, increasing short-term test detection rate, and helping testers optimize test resources.
[0004] With the continuous expansion of the scale of software systems and the increasing complexity of functions, as well as the popularity of continuous integration (CI), traditional recommendation methods face significant challenges. These methods usually only use a few test case features such as historical records, historical execution times, etc. On the one hand, these methods lack multi-dimensional analysis of complex test environments; on the other hand, these methods have poor dynamic adaptability and cannot respond to frequent code changes in a timely manner.
[0005] Therefore, the industry is actively exploring intelligent recommendation methods based on machine learning and code analysis to improve the accuracy and automation level of test case recommendation. For example, supervised learning or clustering algorithms are used to classify and prioritize test cases. However, these methods often struggle to handle dynamic changes and uncertainties in the test environment. In addition, traditional machine learning methods often lack the ability to optimize in the long term and cannot dynamically adjust the recommendation strategy based on feedback during the testing process, resulting in limited test efficiency improvement.
[0006] In recent years, deep reinforcement learning has shown significant advantages in many fields due to its powerful sequence decision-making and adaptive optimization capabilities. Through the continuous interaction between the agent and the environment, the technology can dynamically optimize the decision-making strategy, providing a new approach to solving high-dimensional state space and dynamic evolution problems that traditional testing methods cannot handle. However, there are still some key technical bottlenecks in current research on test case recommendation based on deep reinforcement learning: at the input representation level, existing methods often only establish a preliminary relationship between test cases and code, failing to establish deep connections between test cases and code changes, defect patterns, and code meanings, resulting in a disconnect between the recommended results and the actual risks of the code; at the strategy optimization level, current methods focus on the local effectiveness evaluation of a single test case, ignoring the diversity and complementarity of the test case set as a whole, and lack consideration of the redundancy between test cases; at the dynamic adaptation level, the exploration strategy of deep reinforcement learning lacks understanding of the code evolution rules, resulting in a large amount of ineffective exploration at key nodes such as architecture changes.
[0007] The present application provides a novel large-scale complex software system test case recommendation framework based on deep reinforcement learning, which provides analyzable deep code features, establishes the essential relationship between test cases and code changes, and defect patterns, and has group-level test case optimization capabilities, considering the complementarity and redundancy between test cases, and dynamic environment adaptation capabilities to automatically adjust the recommendation strategy according to code evolution. These capabilities will enable more intelligent and efficient test case recommendation, significantly improving the defect detection efficiency and test resource utilization of software testing in a continuous integration environment. SUMMARY
[0008] Objectives of the present application: The present application provides a large-scale complex software system test case recommendation method based on deep reinforcement learning, which analyzes test cases and related code to form a multi-level and rich test case feature set, and constructs a multi-cycle adaptive training deep reinforcement learning model to obtain test case recommendation results. The model continuously learns through rewards and eventually forms an environment-adaptive test case recommendation.
[0009] Technical solution: The present application is a large-scale complex software system test case recommendation method based on deep reinforcement learning. In the software continuous integration (CI) environment, the specific implementation steps for each version test cycle are as follows: Step 1: Collect software source code and test cases of historical and current versions, organize related information, and form formatted data files.
[0010] Step 2: Extract and construct model input data. The model input is divided into two levels: use cases and code. The data at these two levels are linked through a "use case-code graph" to ultimately form a comprehensive input dataset with hierarchical relationships.
[0011] Step 3: Input the graph structure data "use case-code graph" into the graph feature extractor to obtain the use case-code association features.
[0012] Step 4: Input all data into the use case ranking model based on deep reinforcement learning to obtain the recommended use cases for the next step.
[0013] Step 5: Update the dynamic input data based on the use case selection in the current step.
[0014] Step 6: Perform a sorting loop, repeating steps 3-5, to gradually select test cases and finally form a recommended sequence of test cases.
[0015] Step 7: Execute the test cases in the recommended order, obtain information such as execution results, code coverage, and execution time, and then format the data.
[0016] Step 8: Repeat steps 3-7 to conduct a training loop. During the training loop, calculate the reinforcement learning reward based on the difference between the model's recommended results and the actual execution results, and conduct adaptive training on the model.
[0017] Step 9: In the new testing cycle, update the source code version and test case version, and repeat steps 1-8.
[0018] Through the above steps, this invention can effectively solve the problem of recommending and ranking a large number of test cases based on a combination of multiple criteria such as code defects and time constraints. Furthermore, as software versions evolve, the model can be continuously and dynamically trained, thereby providing test case recommendations that are more adapted to the current version. This test case recommendation method helps software testers to promptly identify faults in the software, avoid repeatedly testing similar test cases, and ultimately improve the overall efficiency of testing work.
[0019] The specific steps for "collecting historical and current software source code and test cases, organizing relevant information, and forming a formatted data file" in step 1 are as follows: Obtain the current version of the software source code and test case code, and compile statistics on filenames, class names, and test case names; simultaneously, use version control tools to obtain development information (change content, time, logs, etc.), format it, and store it in a JSON file. Extract the historical execution results and historical execution times of the test cases, format and store them in a CSV file, and maintain an overall information table to record the addition, deletion, and execution status of test cases for each version.
[0020] Step 2, which involves "extracting and constructing model input data, with model input divided into two levels: use cases and code. The data at these two levels are linked through a 'use case-code graph,' ultimately forming a comprehensive input dataset with hierarchical associations. Initializing some dynamic input data," is specifically implemented in the following five steps: 1) Construct a hierarchical input for use cases, including three types of data: basic information, historical execution data, and static analysis features. Basic information features and historical execution data are integrated from current and historical version use case information, including use case name embedding vectors, use case age, and historical failure rate. Static analysis features are obtained from static analysis tools and include over 40 specific features such as average lines of code, average cyclomatic complexity, and number of static methods.
[0021] 2) Construct code-level input, including three types of data: code change information, code static features, and code defect scanning. Code change information covers the average number of lines changed, the average change time, and the number of related log lines; code static analysis features are obtained by static analysis tools and include more than 40 specific features such as the average number of lines of code, the average cyclomatic complexity, and the number of static methods; code defect scanning features are obtained by code defect scanning tools to obtain the number of potential defects in the code class.
[0022] 3) Merge test cases and source code, use dependency analysis tools to obtain code dependencies, form a dependency network, and construct a "test case-code graph". This graph uses classes as nodes and dependencies as edges. Node features integrate basic attributes and metrics, and edge weights reflect call intensity, ultimately forming a unified data representation that supports coverage analysis.
[0023] 4) Extract the use case coverage probability tree from the "use case-code dependency graph", calculate the estimated probability of use case coverage of each code class, construct the use case coverage probability matrix, and describe the coverage of use cases to code.
[0024] 5) Constructing input data for the deep reinforcement learning model: Integrate fixed input data and initialize dynamic input data. Summarize the data extracted from 1) to 4) to construct a version of fixed input data, and initialize dynamic input data that changes with the model output, including use case selection state vectors and probability coverage contributions.
[0025] Step 3, specifically "inputting the graph structure data 'use case-code graph' into the graph feature extractor to obtain use case code association features," is implemented as follows: The graph structure data "use case-code graph" is used as input, and a subtree attention graph neural network (STAGNN) is employed to extract features. The weighted coverage probability contribution of the use cases is calculated. This feature describes the weighted contribution of the current use case to the increase in use case set coverage, given a fixed set of selected use cases. When selecting the first use case, the weighted coverage probability contribution value needs to be initialized.
[0026] The specific steps for step 4, "inputting all data into a deep reinforcement learning-based use case ranking model to obtain recommended use cases for the next step," are as follows: All data is input into the deep reinforcement learning model. The model's input consists of the features obtained in steps 2-3, including the fixed-version input data and dynamic input data obtained in step 2, as well as the graph-structured data "use case-code graph" obtained in step 3. The model outputs a score vector, and the recommended use cases for the next step are obtained based on the magnitude of each element in the score vector.
[0027] Specifically, step 5, "update the dynamic input data based on the test case selection in the current step," is implemented as follows: based on the current test case selection, update the dynamic input data, including the test case selection state vector and the test case probability coverage contribution.
[0028] The specific steps for "conducting a sorting loop, repeating steps 3-5, gradually selecting test cases, and finally forming a recommended test case sequence" in step 6 are as follows: Conduct a sorting loop, repeating steps 3-5 in each loop, inputting different features into the reinforcement learning-based test case sorting model, obtaining the test cases to be selected in the next step, updating the dynamic input data, and then repeatedly inputting the data into the model to select new test cases, gradually forming a recommended test case sequence until all test cases are included in the recommended test case list.
[0029] Step 7, "execute test cases in the recommended order to obtain execution results, code coverage, execution time, and other information, and format the results," is implemented as follows: Execute test cases in the recommended order to obtain a list of test case execution results, a list of execution times, and a list of code coverage. Format the obtained information and store it in JSON format.
[0030] Step 8, "Repeat steps 3-7 to conduct a training loop. In the training loop, calculate the reinforcement learning reward based on the difference between the model's recommendation results and the actual execution results, and conduct adaptive training on the model," is implemented as follows: A training loop is conducted, with the steps identical to the sorting loop, except that the model is trained only after the test case recommendation list is completed. Reinforcement learning uses rewards for training, calculated based on the difference between the model's recommendation results and the actual execution results, enabling the model to provide stronger recommendations for test cases with failures, shorter execution times, and higher coverage. Adaptive training determines whether to conduct another training loop based on the model's recommendation performance during training. After training, the model parameters are saved to the pth file.
[0031] Specifically, step 9, "In the new test cycle, update the source code version and test case version, and repeat steps 1-8", is implemented as follows: In each subsequent continuous integration version, repeat data collection (steps 1-2), sorting loop (steps 3-6), test execution (step 7), and training loop (step 8) to complete the test case recommendation for each test cycle and dynamically update the model with the version.
[0032] The advantages and beneficial effects of this invention are as follows: This invention provides a test case recommendation method for large-scale complex software systems based on deep reinforcement learning. By providing parsable multi-layered features of test cases, code, and defects, the model develops a deep understanding of test cases. Simultaneously, it constructs dynamic features to describe selected test cases, enabling the model to comprehensively consider the complementarity and redundancy among test cases, thus improving the group-level test case recommendation capability. Furthermore, through a multi-loop adaptive training reinforcement learning structure, this invention possesses strong adaptability to dynamic environments, enabling automatic test case recommendation based on code rendering. These enhanced capabilities achieve more intelligent and efficient test case recommendation, contributing to improved defect detection efficiency and test resource utilization in continuous integration environments. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is a flowchart of the method provided in an embodiment of the present invention.
[0035] Figure 2 This is a schematic diagram illustrating the principle of a test case recommendation method based on deep reinforcement learning provided in an embodiment of the present invention.
[0036] Figure 3 This demonstrates the implementation effects of the present invention on multiple datasets, using APFD and APFDc, commonly used industry metrics for test case ranking, with the comparison method derived from TSE'2023: Scalable and Accurate Test Case Prioritization in Continuous Integration Contexts. Detailed Implementation
[0037] Exemplary embodiments will be described in detail below. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention; rather, they are merely examples of apparatuses and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0038] This invention provides a test case recommendation method for large-scale complex software systems based on deep reinforcement learning. To make the objectives, technical solutions, and advantages of this invention clearer, the embodiments of this invention will be described in detail below with reference to the accompanying drawings. Figure 1 The implementation process of this method is demonstrated. Figure 2 The specific principles and key steps are illustrated as a supplement: Step 101: For the current version of the software source code, obtain the code content and count all file names and code class names, storing them in a JSON file. Then, using version control tools such as Git, obtain relevant information about the current version's code development, including version change details, change times, and log information, format it, and store it in a JSON file.
[0039] For the current version of the test cases, retrieve the code content and count all test case names, organized by class, and store them in a JSON file. Then, extract the execution results and execution time of each test case in previous versions. The execution results are described as the number of test case failures, which are then formatted and stored in a CSV file.
[0040] Maintain a table containing overall test case information, stored in CSV format. This table includes statistics on the usage and execution of all test cases from the initial version to the version under test, and is used to query the historical execution status of test cases added or deleted between versions.
[0041] Step 102: Extract and construct model input data. Input data is divided into use case level and code level. Use case level data includes: use case execution history and static use case analysis; code level data includes: code defect scanning and static code analysis. The use case level and code level data are connected by constructing a "use case-code graph." Using this graph for comprehensive analysis generates coverage-related input features.
[0042] 1) Analyze the initially extracted code and use case information to form features, including name embedding vectors, number of code changes, use case age, and use case failure rate.
[0043] The initially extracted code and use case information is analyzed. Based on the version code and use case information, the average number of lines changed (the average number of lines of code changed in each previous version), the average change time (the average time taken for code changes in each version), and the number of related log lines (the total number of log records associated with code changes) are calculated and integrated into basic code characteristics. and basic features of use cases (This integration simply concatenates different feature values of the same code class into the same line, without any additional processing.)
[0044] Based on the execution results of each test case, calculate the historical failure rate of the test case (the proportion of the number of times the test case failed to execute in history to the total number of executions), the age of the test case (the time span from the first execution of the test case to the present), and the historical average execution time of the test case (the average time spent on each execution of the test case in history), and integrate them into a historical execution matrix of the test cases (here, integration is simply concatenating different feature values of the same test case into the same row, without any additional processing).
[0045] For English software source code class names and test case names, obtain a BERT pre-trained language model. For each name, obtain a name embedding vector of length 50, and construct code class name embedding data accordingly. Data embedded with test case class name .
[0046] 2) Using code measurement tools and static analysis tools, extract static features and defect information of software code and test cases by class.
[0047] Extract code metric features from software source code using code metric tools, on a class-by-class basis. Software code metrics are mainly divided into three categories: code size, cyclomatic complexity, and object-oriented metrics. The current version of the software source code files is scanned to obtain 40 specific characteristics, including: average number of lines of code, average cyclomatic complexity, number of static methods, etc.; the current version of the software source code classes are scanned to obtain forty specific characteristics, including: average number of lines of code, maximum nesting, maximum inheritance tree, etc., stored in CSV format.
[0048] Using code metrics tools, extract code metric features of software test cases, class by class. Test case metrics are mainly divided into three categories: code size, cyclomatic complexity, and object-oriented metrics. The test case code files of the current version are scanned to obtain forty specific features, including: average number of lines of code, average cyclomatic complexity, number of static methods, etc.; the software source code classes of the current version are scanned to obtain 40 specific features, including: average number of lines of code, maximum nesting, maximum inheritance tree, etc., stored in CSV format.
[0049] Static analysis tools are used to scan and analyze the software source code, obtain static analysis defect information, record the number of defects obtained from static analysis in the code class, and store them in CSV format.
[0050] 3) Merge test cases and source code to form a dependency network and build a 'test case-code graph'.
[0051] By merging test cases and source code, and using dependency analysis tools to obtain class-level code dependencies, multiple ternary dependency groups are obtained, represented as follows: ,in, and These are the starting point class and the ending point class, respectively. This represents the number of dependencies (such as method calls, field accesses, etc.) between the starting class and the ending class.
[0052] Establish a weighted directed graph, where: graph nodes are code classes or test case classes; node features combine basic features and metric features; code class node features include basic code features. and code metrics Test case class node features include basic test case features. and use case metrics The directed edges of the graph are constructed between the start class (start) and the end class (target) that have a calling relationship, and the edge weight is defined as the number of dependencies. Store the "use case-code dependency graph" in JSON format.
[0053] 4) Extract the test case coverage probability tree, calculate the estimated coverage probability of the test cases for each code class, and construct the test case coverage probability matrix.
[0054] Extract the use case coverage probability tree from the "use case-code dependency graph". Using each use case node in the use case-code dependency graph as the root node, find the node's coverage probability. l The subtrees form a use case coverage probability tree structure. The use case coverage probability tree is a structural subgraph of the use case-code dependency graph, differing only in edge weights. The edge weights of the use case coverage probability tree describe the estimated probability that the root node use case k reaches the destination class j. For those located at the th The first layer Code Class Estimating probability The formula is as follows:
[0055] in, for The parent node, when hour, As the root node, . for and Edge weights between them for and Edge weights between them For any node at level i+1, Calculated the nodes The sum of edge weights to all nodes at level i+1.
[0056] Arrange the edge weights of the t example trees into a matrix to form the covering probability matrix:
[0057] in, To estimate the probability of reaching the destination class j (n classes) from each root node use case k (a total of t use cases), a probability coverage matrix of size t×n is formed. .
[0058] 5) Constructing input data for deep reinforcement learning models: Integrate fixed input data and initialize dynamic input data.
[0059] Summarize the data extracted from 1) to 4) to construct a version-fixed input data. This includes: use case name embedding Static characteristics of use cases Historical execution of test cases .
[0060] Dynamic input data refers to input data that changes with the model's output and needs to be initialized before input, including: use case selection state vector. Contribution of selected test case probability coverage Where c represents the nth round of the sorting / training loop, at which point... Use Case Selection Vector Each value in the vector corresponds to a test case in the current version, describing whether the corresponding test case has been selected. The test case selection vector is initialized to an all-zero vector, representing the initial state where no test cases are selected, i.e.:
[0061] Coverage probability contribution Describe each use case in the currently selected use case set. Based on this, the coverage probability of each code class is calculated. Initially, the selected case set... The initialization formula is the probability coverage matrix. :
[0062] Step 103: Input the 'use case-code dependency graph' into the graph neural network, extract the graph subtree features, and calculate the weighted coverage probability contribution of the use cases.
[0063] Using the "use case-code dependency graph" as input, the STAGNN subtree attention graph neural network is used to extract features, resulting in graph subtree features. .in, This represents the dimension of the neural network output vector.
[0064] segmentation Code subtree features and using example tree features For code graph subtree features, calculate the weighted coverage probability contribution of use cases. The formula is as follows:
[0065] This feature describes the weighted contribution of the current use case to the growth of use case set coverage, given that the selected use case set TC is determined.
[0066] Step 104: Input all the data into the deep reinforcement learning model to obtain the recommended use cases for the next step.
[0067] A deep reinforcement learning model is constructed. All inputs to the model are the states of the reinforcement learning process, which in this invention include both fixed and dynamic inputs. In round c, the data input to the deep reinforcement learning model includes: fixed input data. Use Case Selection Vector Weighted Coverage Probability Contribution .
[0068] Model outputs score vector Each test case is assigned a score, with higher scores indicating higher priority for selection in the current round. The reinforcement learning action in round c is to select the test case k with the highest score, as shown in the following formula:
[0069] Where i is the unique index of the test case, and t is the total number of test cases. This formula iterates through the score vector. Returns the index k of the use case with the highest score.
[0070] When using a model, if there are already well-trained parameters, use the corresponding parameters; otherwise, use random parameters and update them during subsequent training.
[0071] Step 105: Based on the current test case selection, update some model input data, including: test case selection state vector and test case probability coverage contribution.
[0072] Update use case selection vector Based on the selected test case index. Update the use case selection vector .
[0073] Update test case probability coverage contribution , No. The row update formula is as follows:
[0074] in, Contribute to the probability coverage of use cases in round c+1. express Update line k, This represents the joint probability among the contributions of each use case probability coverage.
[0075] Coverage probability contribution Describe each use case in the currently selected use case set. Based on this, the coverage probability of each code class.
[0076] Step 106: Perform a sorting loop, repeating steps 3-5, to gradually select test cases and finally form a recommended sequence of test cases.
[0077] A sorting loop is performed, in which different features are input into the graph neural network (step 3) and the reinforcement learning model (step 4) in each loop. After obtaining the test cases to be selected for the next step, the input data is updated (step 5). Then, the input and selection of test cases are repeated to gradually form a recommended test case sequence until all test cases are included in the recommended test case list. .
[0078] Step 107: Execute the test cases in the recommended order, obtain the execution results, execution time and other information, and format them.
[0079] Execute the test cases in the recommended order, and use the Surefire plugin to obtain a list of test case execution results. Failures Each element represents the number of failures for the corresponding test case, as well as a list of execution times. Times Each element represents the execution time of the corresponding test case. The obtained information is formatted and stored in JSON format.
[0080] Step 108: Repeat steps 3 through 7 to conduct a training loop. Compare the recommended results from the training loop with the actual execution results, calculate the reinforcement learning reward, and conduct adaptive training on the model. Based on the model's performance after training, decide when to stop training and save the training parameters upon completion.
[0081] The training loop follows the same steps as the sorting loop, except that the model is trained only after the use case recommendation list is completed.
[0082] Reinforcement learning uses rewards for training. For each test case k in the test case recommendation list, a reinforcement learning reward is designed. as follows:
[0083] in, This represents the reward value for test case k; This represents the number of execution failures for test case k. This indicates the selection status of the i-th test case after selecting test case k (usually 1 indicates selection, 0 indicates non-selection); FTS represents the set of all failed test cases in the current version, defined as... Here, x is the index of the test case. It represents the number of execution failures for test case x. Indicates the size of the set; This indicates the rank of test case k in the current set of failed test cases (FTS) based on execution time (the shorter the execution time, the higher the rank, and the lower the value). The calculation formula is as follows: Where j is the index of other use cases besides k in the Failed Use Case Set (FTS). and These represent the execution times of test case j and test case k, respectively. I(·) is an indicator function (returns 1 if the condition is true, otherwise 0). This indicates the ranking of test case k in terms of execution failure frequency within the current set of failed test cases (FTS). The calculation formula is as follows: Where j is the index of other use cases besides k in the Failed Use Case Set (FTS). and These represent the number of execution failures for test case j and test case k, respectively.
[0084] Based on the model's performance during training, a decision is made whether to run another training cycle. Model performance is represented by testing efficiency P, which is the minimum number of rounds required to discover all failed test cases. (This is also the minimum number of test cases required to find all failed test cases) divided by the total number of test cases t, as shown in the formula below:
[0085]
[0086] in, This represents the number of execution failures for test case i. This represents the total number of failures across all use cases.
[0087] Give the tolerance bound for conducting the i-th training cycle. ,if If the training cycle continues, then retraining is required. The larger the number of training iterations (i), the smaller the tolerance threshold. The looser the formula, the better:
[0088] in, The tolerance threshold represents the threshold at the (i-1)th training epoch and is the base value for calculating the threshold at the current epoch. ΔTb_i represents the tolerance threshold increment at the i-th epoch, which is a piecewise function determined by the interval containing training epoch i, with the following specific values:
[0089] After training, the model parameters are saved to the pth file.
[0090] Step 109: In the new testing cycle, update the source code version and test case version, and repeat steps 1 to 8.
[0091] In each subsequent continuous integration version, the data collection (steps 1 to 2), sorting loop (steps 3 to 6), test execution (step 7), and training loop (step 8) are repeated to complete the test case recommendation for each test cycle and dynamically update the model with each version. Specific implementation examples: This method can be applied to the testing phase of continuous integration processes in various software applications, without limitations on code type or software size. Taking the open-source project Angel as an example, it is a high-performance distributed machine learning and graph computing platform designed based on the parameter server concept. Its GitHub repository publicly discloses all code and the continuous integration process. This project is large-scale, with 336,000 lines of effective code. Furthermore, its continuous integration process is active, with over 3,000 commits and over 300 builds completed; each build contains an average of 33 test cases, and over 40% of builds encounter test case execution failures.
[0093] In step 101, obtain the source code of the Angel open-source project from the GitHub repository (https: / / github.com / Angel-ML / angel). Select an earlier version as the version to implement the method (the build version hash value used in this embodiment is c8c87ce82c5791605fb83326b392328372d1d6bf). Use the Git version control tool to obtain all the project source code and test cases for this version. Project source code files include angel-ps / core / src / main / java / com / tencent / angel / PartitionKey.java and angel-ps / core / src / main / java / com / tencent / angel / exception / UnvalidRowSplitException.java; code class names include com.tencent.angel.AngelDeployMode and com.tencent.angel.RunningMode; test classes include com.tencent.angel.psagent.UpdateRowsTest and com.tencent.angel.ml.mixedlogsticregression.MLRTest.
[0094] Collect development-related information, such as the log message "remove some unused uts", the modified classes com.tencent.angel.ps.storage.vector.ServerRowStorageFactory and com.tencent.angel.ps.storage.vector.storage.LongFloatVectorStorage, and the start time "2019-07-30 08:31:42".
[0095] The historical execution results and execution times of the test cases are obtained from the version control on GitHub. For example, the historical average execution time of the test case com.tencent.angel.psagent.UpdateRowsTest is 23,636 milliseconds, and all historical execution results are pass; the historical execution time of the test case com.tencent.angel.ml.regression.LinearRegTest is 57,446 milliseconds, and 7 out of 8 historical executions failed.
[0096] In step 102, the Understand code metrics tool and the SpotBugs defect static analysis tool are used to obtain the corresponding features.
[0097] Use the Understand code metrics tool to extract test case features. For example, the test case com.tencent.angel.ml.gbdt.GBDTTest has an average cyclomatic complexity of 1, 162 lines of code, and 5 executable unit declarations; the test case com.tencent.angel.ml.matrix.psf.ComplexMatrixTest has an average cyclomatic complexity of 3, 232 lines of code, and 4 executable unit declarations.
[0098] Use the Understand code metrics tool to extract code features. For example, the code class com.tencent.angel.AngelDeployMode has an average cyclomatic complexity of 1, 27 lines of code, and 2 executable unit declarations; the code class com.tencent.angel.client.yarn.AngelYarn Client has an average cyclomatic complexity of 3, 581 lines of code, and 15 executable unit declarations.
[0099] Extract the historical execution matrix of the test cases, such as the historical failure rate of the test case com.tencent.angel.ml.regression.LinearRegTest = 87.5%, the test case age = 142.4 days, and the historical average execution time = 57446 milliseconds.
[0100] For English software source code class names and test case names, a name embedding vector of length 50 is generated. For example, the embedding vector of the test case com.tencent.angel.ml.regression.LinearRegTest is [-0.046161454170942307,0.22073635458946228,0.7051100730895996,0.6886194944381714, -0.04231603816151619, -1.0667829513549805, -0.9599848389625549, -0.608344316482544, -2.758718729019165, -0.06388771533966064, -0.7003626227378845, -1.3481708765029907, 0.33264732360839844, 0.039630524814128876, 1.1110708713531494, 0.22463679313659668, 0.09389101713895798, -0.5387787818908691, -0.5745990872383118, -0.05319201201200485, -0.16376641392707825, 1.7017667293548584, -0.7711042761802673, -0.9471083283424377, -0.6767618060112, 0.27118730545043945, -0.6985378861427307, 0.8823422789573669, 0.9890851974487305, -0.06172434240579605, -0.19897758960723877, 2.16127610206604, 0.3960217833518982, -0.2679012417793274, 0.5352341532707214, 0.547856330871582, -0.39032870531082153, 0.04570045322179794, 0.7260459065437317, 0.47480863332748413, -0.651736855506897, -0.29902374744415283, 0.878838062286377, -0.5488066077232361, 0.32204240560531616,0.43375274538993835, -0.027578279376029968, -0.3081969916820526, -0.14496232569217682, 0.48688268661499023,].
[0101] Using the SpotBugs static analysis tool to scan the software, the number of static analysis defects in the code was obtained. For example, there are 2 potential defects in the class com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplitFactory.
[0102] The Understand tool is used to obtain the static dependencies of the software. For example, the code class `com.tencent.angel.api.python.PythonRunner` depends on four other code classes: `com.tencent.angel.AppSubmitter`, `com.tencent.angel.exception.AngelException`, and `com.tencent.angel.api.python.PythonRunner` are each called once, and `com.tencent.angel.conf.AngelConf` is called four times. Each class is numbered, and a "use case-code dependency graph" is formed based on the dependencies. For example, the dependency of class `com.tencent.angel.api.python.PythonRunner` (number 18) on class `com.tencent.angel.conf.AngelConf` (number 253) is stored as an edge (18, 253, 4), with `com.tencent.angel.api.python.PythonRunner` as a node. Its features are composed of the features extracted in the above process. By filtering the dependencies related to a specific use case from the "use case-code dependency graph," a use case coverage probability tree can be obtained.
[0103] In steps 103, 104, and 105, the above features are input, and the score vector is output. Given the values [-0.0646, 3.4411, 1.1517] (taking the output of three test cases as an example, with indices 2, 9, and 21 respectively), the index of the test case selected in the current round is 9, and this test case is com.tencent.angel.ml.regression.LinearRegTest. Update the test case selection vector [0, 1, 0], and update the test case probability coverage contribution.
[0104] In step 106, taking the output of the above three test cases as an example, test cases are selected step by step. In the 16th round, test case 21 is selected and the test case selection vector is updated to [0, 1, 1]. In the 23rd round, test case 2 is selected and the test case selection vector is updated to [1, 1, 1].
[0105] In step 107, test cases are executed sequentially. For example, the test case com.tencent.angel.ml.regression.LinearRegTest is executed first, and the execution result is failure, with an execution time of 618050 milliseconds. The model recommendation is correct. Based on the actual results, the evaluation metrics for this ranking are calculated as APFD=0.9193 and APFDc=0.7308.
[0106] APFD and APFDc are two important metrics for evaluating the effectiveness of test case prioritization. The core objective of APFD is to maximize the failure detection rate by prioritizing the test cases most likely to fail as high as possible; while APFDc, building on APFD, further considers the execution time cost of test cases, aiming to minimize the total time required to detect failures.
[0107] The formula for calculating APFD is:
[0108] Where APFD represents the average percentage of faults detected; a higher value indicates better sorting efficiency. n is the total number of test cases, and m is the total number of faults. It is the location of the first test case that detects the i-th fault.
[0109] The formula for calculating APFDc is:
[0110] in, This represents the average percentage of faults detected, including costs. It is the execution time of the first test case that detects fault i. It is the sum of the execution times of all test cases. It is the sum of the execution times of all test cases that detected faults.
[0111] In step 108, a training loop is performed, and the reward is calculated each time, such as [523, 87, 315, 642, 12, 789,45, 256, 431, 23, 567, 98, 345, 712, 5, 478, 156, 67, 589, 32, 423, 123, 654,78, 389, 234, 56, 701, 189, 45, 512, 267, 89, 445, 167, 34, 598, 278, 76,488, 199, 61, 533, 312, 41, 677, 221, 39, 611, 144]. The model stops training after four training cycles.
[0112] In step 109, tests were conducted on 50 versions of the Angel code, with the APFD sequence being [0.967741935483871, 0.967741935483871, 0.9583333333333333, 0.9605263157894738, 0.9428571428571428, 0.9736842105263158, 0.9736842105263158, 0.9736842105263158, 0.9655172413793104, 0.9736842105263158, 0.9736842105263158, 0.9761904761904762,0.9285714285714286, 0.6904761904761906, 0.9761904761904762,0.9523809523809524, 0.9285714285714286, 0.9761904761904762,0.9285714285714286, 0.9761904761904762, 0.9285714285714286,0.9285714285714286, 0.9761904761904762, 0.9729729729729729,0.4599999999999996, 0.6476257142857144, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.8157894736842105, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, 0.86, [0.86], with a mean of 0.8830; the APFDc sequences are [0.7548249936635546, 0.7617790398779037, 0.9425789565132028, 0.9837963679758754, 0.9022469062897611, 0.7900778572534726, 0.9904199890338016, 0.9167903440755997, 0.7134200180115173, 0.9882099613896558, 0.9176719093846369, 0.9783751119336754, 0.8770942262765602, 0.4736798347435135, 0.9331699785888099,0.7672335227405745, 0.8190277512583739, 0.9778632286222471,0.8893286890436986, 0.9784281956654365, 0.828065567291985,0.8778212382817853, 0.9205726487193541, 0.9896892125437599,0.4558836590711304, 0.7616162506218117, 0.9257050435083526,0.9210460868644053, 0.9235667032445848, 0.9105720506314958,0.9262010551408972, 0.92141469657763, 0.9281321382491413, 0.9145816525289506,0.9130742402189848, 0.8968181045404132, 0.8991430217987681,0.9137592249071184, The values are: 0.8906417750668114, 0.914254172857517, 0.9004762882852671, 0.8987963559199799, 0.8999068366266545, 0.9295205898199664, 0.90808291998207, 0.9020418995943162, 0.9253275243353924, 0.9131668855757811, 0.919424479514778, 0.8908713973202366, with a mean of 0.8823. The results demonstrate the effectiveness of this method in test case recommendation.
[0113] Similarly, the invention was validated in several publicly available large code repositories, and the results were compared with benchmark results reported in the TSE '23 paper. Figure 3 As shown, this method achieves significant improvements in both APFD and APFDc metrics, and this comparison fully demonstrates the effectiveness and superiority of this method in test case ranking.
[0114] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for recommending test cases for large-scale complex software systems based on deep reinforcement learning, characterized in that: The steps are as follows: Step 1: Collect historical and current software source code and test cases, organize relevant information, and form a formatted data file; Step 2: Extract and construct model input data; The model input is divided into two levels: use cases and code. The data at these two levels are linked through a "use case-code diagram" to form a comprehensive input dataset that is interconnected between the levels. Step 3: Input the graph structure data "use case-code graph" into the graph feature extractor to obtain the use case-code association features; Step 4: Input all data into the use case ranking model based on deep reinforcement learning to obtain the recommended use cases for the next step; Step 5: Update the dynamic input data based on the use case selection in the current step; Step 6: Perform a sorting loop, repeating steps 3-5, to gradually select test cases and finally form a recommended sequence of test cases; Step 7: Execute the test cases in the recommended order, obtain the execution results, code coverage, and execution time information, and format them accordingly; Step 8: Repeat steps 3-7 to conduct a training cycle; During the training loop, reinforcement learning rewards are calculated based on the difference between the model's recommendation results and the actual execution results, and adaptive training is performed on the model. Step 9: In the new testing cycle, update the source code version and test case version, and repeat steps 1-8.
2. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 1, the specific steps for "collecting historical and current version software source code and test cases, organizing relevant information, and forming a formatted data file" are as follows: obtain the current version software source code and test case code, and count the file names, class names, and test case names; at the same time, use version control tools to obtain development information, format it, and save it into a JSON file; Extract the historical execution results and execution times of test cases, format and store them as a CSV file, and maintain an overall information table to record the addition, deletion and execution status of test cases for each version.
3. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1 or 2, characterized in that: In step 2, the process of "extracting and constructing model input data" is described. The model input is divided into two levels: use cases and code. The data at these two levels are linked through a 'use case-code diagram', ultimately forming a comprehensive input dataset with hierarchical relationships. The initialization of some dynamic input data is specifically implemented in the following five steps: Step 2.1) Construct the use case hierarchical input, which includes three types of data: basic information, historical execution data, and static analysis features. The basic information features and historical execution data are integrated from the current and historical versions of use case information, including use case name embedding vector, use case age, and historical failure rate of use cases. The static analysis features are obtained by static analysis tools, including features such as average lines of code, average cyclomatic complexity, and number of static methods. Step 2.2) Construct code-level input, including three types of data: code change information, code static features, and code defect scanning. Code change information includes the average number of lines changed, the average change time, and the number of related log lines. Code static analysis features are obtained by static analysis tools, including features such as the average number of lines of code, the average cyclomatic complexity, and the number of static methods. Code defect scanning features are obtained by code defect scanning tools to obtain the number of potential defects in the code class. Step 2.3) Merge test cases and source code, use dependency analysis tools to obtain code dependencies, form a dependency network, and construct a "test case-code graph"; with classes as nodes and dependencies as edges, node features are integrated with basic attributes and metrics, and edge weights reflect call intensity, ultimately forming a unified data representation that can support coverage analysis; Step 2.4) In the "Use Case-Code Dependency Graph", extract the use case coverage probability tree, calculate the estimated coverage probability of the use cases to each code class, construct the use case coverage probability matrix, and describe the coverage of the use cases to the code. Each use case node in the use case-code dependency graph is the root node. The node search... l Layered subtrees form a probability tree structure for use case coverage; A use case coverage probability tree is a structured subgraph of the use case-code dependency graph, differing only in edge weights. The edge weights of the use case coverage probability tree describe the estimated probability that the root node's use case k reaches the destination class j. For those located at the th The first layer Code Class Estimating probability The formula is as follows: ; in, for The parent node, when hour, As the root node, for and Edge weights between them for and Edge weights between them For any node at level i+1, Calculated the nodes The sum of edge weights to all nodes at level i+1; Arrange the edge weights of the t example trees into a matrix to form the covering probability matrix: ; in, To form a probability coverage matrix of size t×n, based on the estimated probabilities of each root node use case k reaching the endpoint class j. ; Step 2.5) Constructing input data for the deep reinforcement learning model: Integrate fixed input data and initialize dynamic input data; summarize the data extracted from steps 2.1) to 2.4) to construct a version of fixed input data. This includes: use case name embedding Static characteristics of use cases Historical execution of test cases ; Dynamic input data refers to input data that changes with the model's output and needs to be initialized before input, including: use case selection state vector. Contribution of selected test case probability coverage Where c represents the nth round of the sorting / training loop, at which point... Use Case Selection Vector Each value corresponds to a test case in the current version, describing whether the corresponding test case has been selected. The test case selection vector is initialized to an all-zero vector, representing the initial state where no test cases have been selected. ; Coverage probability contribution Describe each use case in the currently selected use case set. Based on this, the coverage probability of each code class; in the initial state, the selected case set. The initialization formula is the probability coverage matrix. : 。 4. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 3, characterized in that: In step 3, the specific steps for "inputting the graph structure data 'use case-code graph' into the graph feature extractor to obtain use case code association features" are as follows: the graph structure data "use case-code graph" is used as input, and the STAGNN subtree attention graph neural network is used to extract features and calculate the weighted coverage probability contribution of the use case. This feature describes the weighted contribution of the code features of the current use case to the growth of the use case set coverage, given that the selected use case set is determined. When selecting the first use case, it is necessary to initialize the use case weighted coverage probability contribution value.
5. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 4, the specific steps for "inputting all data into a deep reinforcement learning-based use case ranking model to obtain recommended use cases for the next step" are as follows: input all data into the deep reinforcement learning model; the model input consists of the features obtained in steps 2-3, including the fixed-version input data and dynamic input data obtained in step 2, as well as the graph structure data "use case-code graph" obtained in step 3; the model outputs a score vector, and the recommended use cases for the next step are obtained based on the size of each element of the score vector.
6. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 5, the "update dynamic input data according to the test case selection in the current step" is implemented as follows: Update the dynamic input data according to the current test case selection, including the test case selection state vector and the test case probability coverage contribution; Update use case selection vector Based on the selected test case index Update the use case selection vector ; Update test case probability coverage contribution , No. The row update formula is as follows: ; ; in, Contribute to the probability coverage of use cases in round c+1. express Update line k, This represents the joint probability among the contributions of each use case probability coverage; Coverage probability contribution Describe each use case in the currently selected use case set. Based on this, the coverage probability of each code class.
7. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 6, the specific steps of "conducting a sorting loop, repeating steps 3-5, gradually selecting test cases, and finally forming a recommended test case sequence" are as follows: Conduct a sorting loop, repeating steps 3-5 in each loop, inputting different features into the reinforcement learning-based test case sorting model, obtaining the test cases to be selected in the next step, updating the dynamic input data, and then repeatedly inputting the data into the model to select new test cases, gradually forming a recommended test case sequence until all test cases are included in the recommended test case list.
8. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 7, the specific steps for "executing test cases in the recommended order to obtain execution results, code coverage, and execution time information, and performing formatting processing" are as follows: Execute test cases in the recommended order to obtain a list of test case execution results, a list of execution times, and a list of code coverage; format the obtained information and store it in JSON format.
9. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 8, the specific steps of "repeating steps 3-7 to conduct a training loop; in the training loop, calculating reinforcement learning rewards based on the difference between the model's recommendation results and the actual execution results, and conducting adaptive training on the model" are as follows: The training loop is conducted in the same manner as the sorting loop, except that the model is trained only after the test case recommendation list is completed; reinforcement learning is trained using rewards, which are calculated based on the difference between the model's recommendation results and the actual execution results, enabling the model to provide stronger recommendations for test cases with failures, shorter execution times, and higher coverage. Adaptive training determines whether to run another training cycle based on the model's recommendation performance during training. After training is complete, save the model parameters to the pth file.
10. The method for recommending test cases for large-scale complex software systems based on deep reinforcement learning according to claim 1, characterized in that: In step 9, the phrase "in the new test cycle, update the source code version and test case version, and repeat steps 1-8" is implemented as follows: In each subsequent continuous integration version, repeat the data collection, sorting cycle, test execution, and training cycle to complete the test case recommendation for each test cycle, and dynamically update the model according to the version.