A software-oriented class integration test sequence generation method
Patent Information
- Application Number
- CN202611197336.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-10-13
AI Technical Summary
[0003]然而,云安全软件以面向对象范式开发,涵盖身份认证、访问控制、密钥管理、安全审计、入侵检测等模块,类间依赖关系密集,集成阶段易形成大量复杂环路
在本说明书提供的面向软件的类集成测试顺序生成方法中,本发明创新性地将环路破除问题建模为强化学习的序贯决策过程,通过将表征环路的覆盖情况、依赖边的存在状态及测试桩复杂度信息的子状态输入策略网络,策略网络在动作决策中综合评估依赖边的测试桩成本与依赖边对环路的整体破坏贡献,从而在后续迭代决策中动态调整动作选择,避免传统固定规则一次性破环导致的成本次优问题,最终构建最少的总测试桩成本的类集成测试顺序,从而提高了云安全软件的集成测试效率。
Smart Images

Figure CN122903322A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing technology, and in particular to a method for generating class integration test sequences for software. Background Technology
[0002] In the integration testing of cloud security software, generating the Class Integration Test Order (CITO) is a core issue. Existing methods for generating CITO are typically based on graph theory, abstracting inter-class dependencies into a directed graph. By identifying cycles in the graph and removing dependency edges from those cycles, a cycle-free test order is generated, thereby reducing the cost of test stubs.
[0003] However, cloud security software is developed using an object-oriented paradigm, encompassing modules such as identity authentication, access control, key management, security auditing, and intrusion detection. This results in dense inter-class dependencies, making it prone to forming numerous complex loops during the integration phase. Existing technologies use fixed rules (e.g., prioritizing the deletion of edges with the lowest weight) to break these loops. Since these loops are often intertwined and share dependencies, locally optimal edge deletion decisions may lead to the subsequent deletion of even more high-cost edges. Ultimately, this results in a higher overall test stub cost during cloud security software integration testing, thus hindering the efficiency of cloud security software integration testing. Summary of the Invention
[0004] Therefore, it is necessary to provide a software-oriented method for generating class integration test sequences to address the aforementioned technical problems.
[0005] The following technical solution is adopted in this specification: This specification provides a method for generating class integration test sequences for software, including: Extract all classes and inter-class dependencies in the software under test, and construct a directed graph by treating all classes as vertices and inter-class dependencies as directed edges; identify all strongly connected components (SCCs) in the directed graph; strongly connected components are used to characterize the cyclic dependency clusters of classes in the software under test. Perform a loop search on each SCC to obtain all loops in the SCC and the set of dependencies involved therein; the set of dependencies includes all dependent edges in the loops. Based on all loops, dependency sets, and test stub complexity of each dependency edge in each SCC, a substate of each SCC is constructed; the substate represents the coverage of loops, the existence status of dependencies, and test stub complexity information in vector form. The sub-states of all SCCs are input into a pre-trained policy network, which iteratively generates an action space to indicate the dependent edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed. During training, the policy network determines the reward based on the test stub cost of deleting dependent edges and the contribution of dependent edges to the overall destruction of loops. After all loops of all SCCs in the directed graph are completely destroyed, an acyclic graph is formed. Perform topological sorting on the acyclic graph to obtain the class integration test order.
[0006] Optionally, a loop search is performed on each SCC to obtain all loops in the SCC and the set of dependencies involved, including: For each SCC, initialize the successor list and backtrack pointer for each vertex in the SCC, and create an empty stack; the successor list stores all direct successor vertices of the vertex; the pointer represents an integer index pointing to the position in the successor list; Starting from any vertex, push the vertex onto the stack, and perform a depth-first traversal along the successor pointer of that vertex. After traversing a successor vertex, increment the pointer by 1. When it is detected that the successor vertex of the current vertex is already in the stack, extract all vertices from the successor vertex to the top of the stack as a loop, and record the dependent edges contained in the loop. Once all successor vertices of any given vertex have been processed, pop that vertex from the stack and reset its pointer to 0, backtrack to the previous vertex, and continue processing its unprocessed branches. Once all vertices have been traversed, output all loops in the strongly connected components and the set of their dependencies.
[0007] Optionally, the sub-state includes the loop existence vector, the remaining dependency vector, the current total test stub complexity, and the completion flag; The loop existence vector indicates whether each loop in the corresponding SCC is still intact; The remaining dependency vector indicates whether each dependency edge in the corresponding SCC still exists; The current total test stub complexity represents the sum of the test stub complexities of the currently deleted edges; The completion indicator signifies whether all loops of the SCC have been completely destroyed.
[0008] Optionally, the sub-states of all SCCs are input into a pre-trained policy network to iteratively generate the action space for indicating the dependent edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed, including: All sub-states of SCC are input into a policy network trained through reinforcement learning to generate an action space; the action space includes the action probability distribution of SCC. For any SCC, a binary mask vector is generated based on the remaining dependency vector and completion flag in the substate. The length of the binary mask vector is equal to the action space dimension of the SCC. The index of the dependency edge that has not been deleted and the corresponding position of the empty action are set to 1, and the corresponding position of the index of the deleted dependency edge is set to 0. The action probability distribution of the SCC is multiplied element-wise with the binary mask vector, and then the processed action probability distribution is normalized by the Softmax function to obtain the action to be executed by the SCC; the action to be executed by the SCC represents the dependency edge to be deleted. Update the sub-states according to the actions to be performed, and continue to generate new action spaces based on the updated sub-states until all SCC sub-states indicate that all their loops have been completely destroyed.
[0009] Optionally, the policy network includes a first shared encoder and multiple parallel independent action heads, where one SCC corresponds to one independent action head, and each independent action head includes a first action head and a second action head; the sub-states of all SCCs are input into the policy network trained through reinforcement learning to generate an action space, including: All SCC sub-states are integrated into a global state input to the first shared encoder, and the common features of all SCC sub-states are extracted through the first shared encoder. For any SCC, the general features are input into the first action head of the SCC. The features of the SCC are refined through the first action head. The refined features are then input into the second action head to obtain the action probability distribution. The action probability distribution is used as the action space of the SCC.
[0010] Optionally, the method further includes: During the sub-state update process, the loop existence vector and residual dependency vector with varying lengths are mapped to fixed lengths through the embedding layer; the embedding layer includes concatenated convolutional layers and global average pooling layers.
[0011] Optionally, the training process of the policy network includes: The source code of the sample software is analyzed to generate a sample directed graph. Based on the sample directed graph, multiple sample SCCs and the sub-states of each sample SCC are determined. The sub-states of all sample SCCs are integrated into a global state, and the global state is input into the initial policy network to obtain the global action; the global action includes the action space of each sample SCC. The global state and global actions are input into the initial value network to obtain the global action value; Execute the action for each sample SCC separately, update the sub-state of each sample SCC according to the state transition rule, and calculate the immediate reward for each sample SCC. The current state, action, reward, and next state are stored as experience samples in the experience replay pool, and the parameters of the initial policy network and the initial value network are updated according to the immediate reward, global action value, and target value, respectively. When the preset iteration termination condition is met, training stops, and the initial policy network obtained from training is used as the policy network, and the initial value network obtained from training is used as the value network.
[0012] Optionally, the value network includes a second shared encoder, a feature fusion layer, and multiple independent value heads, with one SCC corresponding to one value head; the global state and global action are input into the initial value network to obtain the global action value, including: The global state and global action are input into the initial value network, the state features of the global state are extracted by the second shared encoder, and the state features and global action are encoded and concatenated in the feature fusion layer. The concatenated features are input into each value head to obtain the value of each sample SCC. Sum the values of each SCC to obtain the global action value.
[0013] Optionally, the instantaneous reward for each sample SCC is calculated, including: For any sample SCC, the loop breaking reward is determined by multiplying the number of loops broken by deleting dependent edges by the reward coefficient. The test stub construction penalty is determined based on the complexity of the test stubs introduced by deleting dependency edges and the cost of indirect dependencies. If all loops in sample SCC are destroyed after the dependent edges are removed, the reward calculation is complete. If the action is invalid, then an invalid action penalty will be determined; The immediate reward is determined based on the loop destruction reward, test pile construction penalty, completion reward, and invalid action penalty.
[0014] Optionally, in the early stage of the policy network training process, a first threshold is used for the reward coefficient, and in the later stage of the policy network training process, a second threshold is used for the reward coefficient; the first threshold is greater than the second threshold; the early stage is the pre-preset number of training iterations in the policy network training process; the later stage is the training process after the early stage.
[0015] Optionally, after determining the directed graph, the method further includes: Calculate the attribute complexity and method complexity of each edge in a directed graph; Calculate the test stub complexity of each edge in the directed graph based on the attribute complexity and method complexity of each edge.
[0016] This specification provides a software-oriented class integration test sequence generation device, including: The parsing and search module is used to extract all classes and inter-class dependencies in the software under test, and construct a directed graph by treating all classes as vertices and inter-class dependencies as directed edges; it identifies all strongly connected components (SCCs) in the directed graph; strongly connected components are used to represent cyclic dependency clusters of classes in the software under test. The loop identification module is used to perform loop search for each SCC to obtain all loops in the SCC and the set of dependencies involved therein; The state construction module is used to construct the sub-state of each SCC based on all loops, dependency sets, and test stub complexity of each dependency edge. The sub-state represents the coverage of loops, the existence status of dependencies, and test stub complexity information in vector form. The loop removal module is used to input the sub-states of all SCCs into the pre-trained policy network and iteratively generate the action space to indicate the dependent edges to be removed in each SCC until the sub-states of all SCCs indicate that all their loops have been completely destroyed. During training, the policy network determines the reward based on the test stub cost of deleting dependent edges and the contribution of dependent edges to the overall destruction of loops. After all the loops of all SCCs in the directed graph are completely destroyed, an acyclic graph is formed. The sorting module is used to perform topological sorting on acyclic graphs to obtain the class integration test order.
[0017] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described software-oriented class integration test sequence generation method.
[0018] This specification provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described software-oriented class integration test sequence generation method.
[0019] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects: In the software-oriented integration test sequence generation method provided in this specification, the present invention innovatively models the loop breaking problem as a sequential decision-making process of reinforcement learning. By inputting the sub-states representing the coverage of the loop, the existence state of the dependent edges, and the complexity information of the test stubs into the policy network, the policy network comprehensively evaluates the test stub cost of the dependent edges and the contribution of the dependent edges to the overall destruction of the loop in the action decision. In subsequent iterative decisions, the action selection is dynamically adjusted to avoid the cost suboptimal problem caused by the one-time loop breaking of traditional fixed rules. Finally, the integration test sequence with the minimum total test stub cost is constructed, thereby improving the integration testing efficiency of cloud security software. Attached Figure Description
[0020] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0021] Figure 1 This document provides a flowchart illustrating a method for generating the order of software-oriented class integration tests. Figure 2 This document presents a flowchart illustrating another method for generating the order of software-oriented class integration tests. Figure 3 This document provides a schematic diagram of an Actor-Critic network architecture. Figure 4 This specification provides a schematic diagram of a computer device for implementing a software-oriented class integration test sequence generation method. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments in this specification without creative effort are within the scope of protection of this application.
[0023] Existing methods mainly fall into three categories: graph theory-based methods, search-based methods, and reinforcement learning-based methods.
[0024] Graph-based methods often only consider the complexity of a single test stub when evaluating the cost of dependency removal, without fully taking into account factors such as the importance of the class and the type of dependency. This results in the generated test sequences being inadequate in terms of cost control and fault detection efficiency.
[0025] Search-based approaches transform the CITO problem into a multi-objective optimization problem, using metaheuristic algorithms such as genetic algorithms, particle swarm optimization, or simulated annealing to search for the optimal test sequence. While these methods can optimize test stub costs to some extent, their search process is random, leading to uncertain test sequence results and slow convergence speed in large-scale systems, making them unsuitable for practical engineering needs. Furthermore, existing search methods typically use only test stub cost as the fitness function, ignoring the business importance or propagation impact of the classes themselves, and failing to prioritize testing critical classes.
[0026] In recent years, reinforcement learning-based methods (such as Deep Q-Network (DQN), Proximal Policy Optimization (PPO), and Soft Actor-Critic (SAC)) have been gradually introduced into the CITO problem, learning the optimal test order policy through agent-environment interaction. However, existing reinforcement learning methods still have the following significant drawbacks:
[0027] Q-value overestimation problem: Value function-based algorithms (such as DQN) are prone to systematic Q-value overestimation, leading to policy bias; Inefficient exploration: Although maximum entropy reinforcement learning methods such as SAC encourage exploration, they are prone to generating a large number of invalid actions in large-scale loop structures, resulting in slow convergence. Objective mismatch: SAC aims to find multiple equivalent optimal solutions, while CITO problems typically require a deterministic unique optimal sequence; The state and action space design is suboptimal: Existing methods directly construct the state space using a global graph structure, which leads to dimensionality explosion and makes training difficult; The reward design is simplistic: the reward function mainly focuses on the cost of test stubs and lacks comprehensive modeling of loop destruction efficiency, class importance, etc.
[0028] Furthermore, existing methods for loop identification and processing often employ traditional depth-first search recursive algorithms, which suffer from problems such as repeated searches, stack overflow, and high space complexity, making it difficult to efficiently handle large-scale strongly connected components (SCCs).
[0029] In summary, existing technologies have significant shortcomings in terms of loop processing efficiency, state-action space modeling, reward function design, and algorithm target matching. There is an urgent need for an efficient, stable, and deterministic method for generating class integration test sequences.
[0030] The purpose of this invention is to address the shortcomings of the prior art by providing a method for inter-class loop deletion and test sequence generation based on SAC reinforcement learning, aiming to solve the following technical problems: 1. To address the problems of low efficiency, repeated searches, and recursive stack overflow in existing CITO methods, a pointer-guided stack-based backtracking algorithm is provided to achieve efficient and lossless identification of all loops and their dependent edges in strongly connected components (SCCs). 2. To address the problem of excessively high state space dimensionality and training difficulties in existing reinforcement learning methods, a hierarchical state space modeling method based on SCC decomposition is proposed. This method decomposes the global state into multiple independent SCC sub-states, significantly reducing the state dimensionality and improving training efficiency. 3. To address the issues of unreasonable action space design and ineffective action interference in existing reinforcement learning methods, a dynamic action masking mechanism is proposed to support the unified processing of variable-length sub-action spaces; 4. To address the problem that existing reward functions are designed in a single way and cannot simultaneously consider the efficiency of loop destruction and the cost of test piles, a two-stage dynamic reward mechanism is constructed to incentivize loop destruction and cost optimization respectively. 5. To address the issues of target mismatch and low exploration efficiency in the CITO problem caused by existing reinforcement learning methods (such as SAC), we use SCC decomposition and parallel decision-making of independent sub-policies to balance exploration and deterministic sequence generation, ensuring rapid convergence to the optimal test order.
[0031] The ultimate goal of this invention is to realize an efficient, stable, and deterministic method for generating class integration test sequences, which significantly reduces the cost of test stub construction, prioritizes testing of critical classes, and improves the efficiency of integration testing for object-oriented software (especially complex systems such as embodied intelligence).
[0032] Based on this, the present invention provides a method for generating class integration test sequences for software, which has the following advantages: First, the present invention employs a pointer-guided stack-based backtracking loop identification algorithm, which can accurately identify all loops in SCC, including simple loops and compound loops. This avoids the problem of incomplete loop destruction caused by missing compound loops in existing methods, improves the completeness of loop identification, and ensures the effectiveness of the integration test order.
[0033] Second, this invention introduces the complexity of test stubs for dependent edges in the construction of sub-states. When selecting actions, the policy network comprehensively considers the effect of loop destruction and the cost of test stub construction. Compared with the greedy method that only targets the number of loops, it can generate a class integration test sequence with lower test stub construction cost, effectively reducing the cost of integration testing.
[0034] Third, this invention uses a policy network for iterative decision-making. Through a state-action-reward reinforcement learning mechanism, it searches for the optimal loop-breaking strategy globally, avoiding the problems of heuristic methods being prone to getting trapped in local optima and the difficulty of parameter tuning. This improves the efficiency and accuracy of generating large-scale object-oriented software integration test sequences.
[0035] Fourth, when applied to cloud security software development, this invention can provide a low-cost test sequence planning for class integration testing of cloud security functional modules, enabling testers to complete incremental integration testing of cloud security modules within a limited time, exposing inter-class interface defects and dependency conflicts as early as possible, and improving the reliability and maintainability of cloud security software. At the same time, this method can be embedded into the continuous integration process of cloud security software as a quality assurance link in the code submission stage, supporting the construction of cloud security training platforms.
[0036] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0037] Figure 1 This is a flowchart illustrating a software-oriented method for generating class integration test sequences, as described in this specification. The method includes the following steps: S101, extract all classes and inter-class dependencies in the software under test, and construct a directed graph by using all classes as vertices and inter-class dependencies as directed edges; identify all strongly connected components (SCCs) in the directed graph; strongly connected components are used to characterize the cyclic dependency clusters of classes in the software under test.
[0038] Specifically, the source code of the software under test is parsed, all classes (Vertices, V) and their dependencies (Edges, E) are extracted, and a directed graph ORD is constructed.<V, E> V represents the set of classes, and E represents the set of dependent edges; each dependent edge e = < v i , v j >Representation class v i Depends on class v j .
[0039] Assign a weight to each dependency edge e, with the weight being the test stub complexity SCplx( v i , v j ).
[0040] After determining the directed graph, the test stub complexity is calculated as follows: calculate the property complexity and method complexity of each edge in the directed graph; based on the property complexity and method complexity of each edge, calculate the test stub complexity of each edge in the directed graph.
[0041] Specifically, the formula for calculating the complexity of the test pile is as follows: in, W A and W M These are the weighting coefficients. ACplx ( v i , v j ) represents the class after normalization. v i and class v j The complexity of the properties between them MCplx ( v i ,v j ) represents the class after normalization. v i and class v j The complexity of the methods between them.
[0042] The Tarjan algorithm was used to perform a depth-first search (DFS) on the directed graph ORD to identify all strongly connected components (SCCs). An SCC is the largest set of nodes in the graph, where every two nodes have a bidirectional path, which is the fundamental reason for the existence of cycles.
[0043] S102, perform a loop search for each SCC to obtain all loops in the SCC and the set of dependencies involved; the set of dependencies includes all dependent edges in the loops.
[0044] In one embodiment, a cycle search is performed on each SCC to obtain all cycles in the SCC and the set of dependencies involved therein. This includes: for each SCC, initializing the successor list and backtracking pointer for each vertex in the SCC, and creating an empty stack; the successor list stores all direct successor vertices of a vertex; the pointer represents an integer index pointing to the position in the successor list; starting from any vertex, push the vertex onto the stack, and perform a depth-first traversal along the successor pointer of the vertex. After traversing a successor vertex, increment the pointer by 1; when it is detected that the successor vertex of the current vertex is already in the stack, extract all vertices from the successor vertex to the top of the stack as a cycle, and record the dependent edges contained in the cycle; when all successor vertices of any vertex have been processed, pop the vertex from the stack and reset its pointer to 0, backtrack to the previous vertex, and continue processing its unprocessed branches; when all vertices have been traversed, output all cycles of strongly connected components and the set of dependencies involved therein.
[0045] Specifically, for each SCC, a pointer-guided stack-based backtracking algorithm is used to accurately identify all internal loops and the set of dependent edges constituting those loops. The algorithm steps are as follows:
[0046] S201: Initialization. Create a successor list `successors[v]` (containing only successor nodes that also belong to this SCC) and a pointer `pointer[v]` for each vertex `v` in the SCC, initially pointing to the first successor node. Create an empty stack `STACK`.
[0047] S202: Select any vertex from SCC and push it onto the stack. S203: Depth-first traversal and loop detection to obtain the top vertex v of the stack.
[0048] a. Obtain the next successor node w to be processed based on pointer[v].
[0049] b. If w is already in the stack, then all vertices from the position of w in the stack to the top of the stack form a cycle. After normalizing this cycle (starting from the smallest vertex number and arranged clockwise), store it in the cycle list ListOfCycle, and record all dependent edges involved in the cycle in ListOfDep.
[0050] c. If w is not on the stack, push w onto the stack and continue the depth-first traversal starting from w.
[0051] S204: Pointer Advancement and Backtracking: After processing w, pointer[v] is incremented by 1. When all successor nodes of vertex v have been processed (i.e., pointer[v] reaches the length of its successor list), v is popped from the stack, its pointer is reset to 0, and backtracking is performed to the previous vertex to continue processing its unprocessed branches.
[0052] S205: The algorithm ultimately outputs the total number of cycles (cycleNo) in the current SCC, a list of all cycles (ListOfCycle), and a list of dependent edges involved in all cycles (ListOfDep). This algorithm has a time complexity of O(n+e) and a space complexity of O(n+e), avoiding the stack overflow risk of recursive algorithms.
[0053] In this embodiment, a pointer `pointer[v]` is maintained for each vertex class to record the position of the currently processed successor node, ensuring that all outgoing edges of each vertex are traversed sequentially and without repetition. An explicit stack `STACK` allocated on the program heap is used to store the vertex sequence on the current search path, replacing the implicit call stack of recursive functions. Loop extraction rule: When a successor node `w` of the current vertex is found to exist in the stack, all vertices from the position of `w` to the top of the stack are extracted, forming a complete loop. Backtracking mechanism: After all successors of a vertex have been processed, the vertex is popped from the stack, and its pointer is reset to 0, achieving precise backtracking to the previous vertex.
[0054] To illustrate this embodiment, consider an example: SCC contains vertices 1, 2, 4, and 5, with edges 1->2, 1->4, 2->5, 5->1, 4->5, and 4->1. Here, visited[i][j] represents the edge from vertex... v i arrive v j Whether this edge has been visited, visited[i][j]=true indicates from vertex v i arrive v jThis edge has already been visited.
[0055] The traversal process includes: Starting from vertex 1, push 1 onto the stack, push the successor node 2 onto the stack, visited[1][2]=true; push the successor node 5 of 2 onto the stack, visited[2][5]=true; the successor node 1 of 5 is already on the stack, visited[5][1]=true, output loop 125.
[0056] If no other successor node for 5 is found, 5 is popped up, and visited[5][ALL]=false.
[0057] Then return to 2. Since 2 has no other successor nodes, pop 2 and visited[2][ALL]=false.
[0058] Returning to 1, the other successor node of 1 is 4, 4 is pushed onto the stack, visited[1][4]=true; the successor node of 4, 1, is already on the stack, visited[4][1]=true, output loop 14.
[0059] Find the other successor node 5 of 4, push 5 onto the stack, visited[4][5]=true; the successor node 1 of 5 is already on the stack, visited[5][1]=true, output loop 145.
[0060] If no other successor node for 5 is found, 5 is popped up, and visited[5][ALL]=false.
[0061] If no other successor node for 4 is found, 4 is popped up and visited[4][ALL]=false.
[0062] If no other successor node is found for 1, then 1 is popped up and visited[1][ALL]=false.
[0063] Similarly, starting from vertex 4, 4 is pushed onto the stack, and the successor node 1 is pushed onto the stack, visited[4][1]=true; the successor node 4 of 1 is already on the stack, visited[1][4]=true, and the loop 41 is output.
[0064] Find another successor node of 1, find 2, push 2 onto the stack, visited[1][2]=true; push the successor node of 2, 5, onto the stack, visited[2][5]=true; the successor node of 5, 1, is already on the stack, visited[5][1]=true, output loop 125.
[0065] If no other successor node for 5 is found, 5 is popped up, and visited[5][ALL]=false.
[0066] Then return to 2. Since 2 has no other successor nodes, pop 2 and visited[2][ALL]=false.
[0067] Returning to 1, since 1 has no other successor nodes, 1 is popped up, and visited[1][ALL]=false.
[0068] Returning to 4, the other successor node of 4 is 5, 5 is pushed onto the stack, visited[4][5]=true; the successor node of 5 is 1, 1 is pushed onto the stack, visited[5][1]=true, the successor node of 1, 4, is already on the stack, visited[1][4]=true, output loop 451.
[0069] Find another successor node of 1 and find 2. Push 2 onto the stack and visited[1][2]=true; the successor node of 2, 5, is already on the stack and visited[2][5]=true. The loop 512 is the same as the loop 125 above, so it is not recorded.
[0070] Then return to 2. Since 2 has no other successor nodes, pop 2 and visited[2][ALL]=false.
[0071] Returning to 1, since 1 has no other successor nodes, 1 is popped up, and visited[1][ALL]=false.
[0072] Returning to 5, since 5 has no other successor nodes, 5 is popped up, and visited[5][ALL]=false.
[0073] Returning to 4, since 4 has no other successor nodes, 4 is popped up, and visited[4][ALL]=false.
[0074] Following the same method, traversal is performed starting from vertices 2 and 3 respectively to find cycles. This embodiment will not be described in detail here.
[0075] S103. Based on all loops, dependency sets, and test stub complexity of each dependency edge in each SCC, construct the sub-state of each SCC. The sub-state represents the coverage of loops, the existence status of dependencies, and test stub complexity information in vector form.
[0076] Each SCC is treated as an independent subproblem. A hierarchical state space and action space are constructed, and the agent is trained using the SAC algorithm to learn the optimal loop destruction strategy.
[0077] State space design: The global state S consists of K sub-states of SCC: in, K Let SCC be the number of SCCs in the directed graph. This indicates that the loop in the first SCC exists as a vector. This represents the residual dependency vector of the first SCC. This represents the total test stub complexity of the first SCC. This indicates the completion of the first SCC. Indicates the first K The loop of each SCC has a vector. Indicates the first K The residual dependency vectors of each SCC Indicates the first K Total test stub complexity of SCC This indicates the completion of the first SCC.
[0078] Loop exists as a vector ( ):one A two-dimensional vector, representing the first... i In SCC Is the loop still intact (1 indicates it is not damaged)? For the corresponding number i The total number of loops within each SCC, where each element indicates whether the corresponding loop still exists (1 = exists, 0 = broken).
[0079] Residual dependency vector ( ):one A two-dimensional vector, representing the first... i Participating in the loop in each SCC Does the dependent edge still exist (1 indicates that it exists)? For the corresponding number i The total number of dependent edges participating in the loop within each SCC, where each element indicates whether the corresponding edge still exists (1 = exists, 0 = deleted).
[0080] Current total test pile complexity ( ): A continuous value, recorded as the value of the first destruction. i The sum of the total weights (test stub complexity) of the deleted edges in each SCC loop.
[0081] Completed mark ( ): A binary variable, denoted by the first... i Has all loops of an SCC been completely destroyed (1 indicates completion, 0 indicates incomplete)?
[0082] S104: Input the sub-states of all SCCs into the pre-trained policy network, iteratively generate the action space to indicate the dependent edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed; the policy network determines the reward based on the test stub cost of deleting dependent edges and the contribution of dependent edges to the overall destruction of loops during training; after all loops of SCCs in the directed graph are completely destroyed, an acyclic graph is formed.
[0083] In one embodiment, the sub-states of all SCCs are input into a pre-trained policy network to iteratively generate an action space indicating the dependency edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed. This includes: inputting the sub-states of all SCCs into a policy network trained by reinforcement learning to generate an action space; the action space includes the action probability distribution of the SCCs; for any SCC, generating a binary mask vector based on the remaining dependency vector and completion flag in the sub-state, the length of which is equal to the dimension of the action space of that SCC. +1), where the index of the dependency edge that has not yet been deleted and the corresponding position of the empty action (valid action) are set to 1, and the index of the deleted dependency edge (invalid action) is set to 0; the action probability distribution of the SCC is multiplied element by element by the binary mask vector, and then the processed action probability distribution is normalized by the Softmax function to obtain the action to be executed by the SCC; the action to be executed by the SCC represents the dependency edge to be deleted; the sub-state is updated according to the action to be executed, and a new action space is generated based on the updated sub-state until the sub-state of all SCCs indicates that all their loops have been completely destroyed.
[0084] Action space design for Policy Network Actors: Global action A is... K The sub-actions of an SCC consist of: Effective action: When When =0, It can be the first i The index of a still existing dependency edge in each SCC (0 ≤ a i < n i ), indicates that the edge is deleted.
[0085] Optionally, It can also be an empty action: when When =1, An empty action indicates that no operation will be performed on the SCC.
[0086] In one embodiment, the policy network includes a first shared encoder and multiple parallel independent action heads, with one SCC corresponding to one independent action head, and each independent action head including a first action head and a second action head; inputting the sub-states of all SCCs into the policy network trained by reinforcement learning to generate the action space includes: integrating the sub-states of all SCCs into a global state and inputting it into the first shared encoder; extracting the general features of all SCC sub-states through the first shared encoder; for any SCC, inputting the general features into the first action head of that SCC; refining the features of the SCC through the first action head; inputting the refined features into the second action head to obtain the action probability distribution; and using the action probability distribution as the action space of the SCC.
[0087] The first shared encoder consists of a fully connected layer and a ReLU activation function, which extracts the common features of all SCC sub-states.
[0088] K Parallel independent action heads: Each independent action head targets a single SCC. The first action head is responsible for refining the features specific to the corresponding SCC, performing local refinement of the features to highlight key information related to the decision of that SCC. The second action head outputs the original action log probabilities (logits) of that SCC. Mask constraint and Softmax: The logits output by the second action head are constrained by the corresponding mask, and then the probability distribution of the sub-actions is output through Softmax.
[0089] Dynamic Action Mask: To prevent invalid actions (such as repeatedly deleting edges that no longer exist) from interfering with training, a dynamic binary mask vector is generated for each SCC. mask i Mark which actions are valid in the current step. mask i Indicates the first i A binary mask vector for each SCC.
[0090] The original action logits are multiplied element-wise by the binary mask vector. The logits corresponding to invalid actions are set to negative infinity. Then, the result is fed into the Softmax function for normalization, so that the final selection probability of invalid actions is strictly 0.
[0091] The dependency edge with the highest probability value is identified as the dependency edge that needs to be deleted, which is the action that SCC needs to perform.
[0092] When SCC executes sub-actions When deleting a dependent edge, update the child state according to the following rules: (1) The deleted dependency edge corresponds to The element value in is set to 0.
[0093] (2) Add test stub complexity for deleted dependency edges SCplx (v, w).
[0094] (3) All cycles containing the deleted dependency edge The element value in is set to 0.
[0095] (4) If Then Set to 1.
[0096] To address the issue of different dimensions in each SCC substate, an embedding layer was designed: during the substate update process, the loop existence vector and residual dependency vector with varying lengths are mapped to fixed-length feature vectors through the embedding layer; the embedding layer includes a cascaded 1×1 convolutional layer and a global average pooling layer.
[0097] Specifically, for variable length Vector (shape 1×) First expand to 1× ×1, then through c c A 1×1 convolutional kernel performs a linear transformation, and finally, global average pooling outputs a fixed-length feature vector. (dimension) c c ); for variable length The vectors are processed in exactly the same way, and the output is... ;in, c c The number of convolution kernels, optionally, c c =32.
[0098] The updated sub-states are then integrated into the global state and input into the policy network to obtain the action space. The sub-states are then updated using the action space until all SCC sub-states indicate that all their loops have been completely destroyed.
[0099] S105. Based on all deleted dependency edges, perform decyclic processing on the directed graph to obtain an acyclic graph; perform topological sorting on the acyclic graph to obtain the class integration test order.
[0100] After the S103-S104 iterations and deletions, the directed graph becomes an acyclic graph. The acyclic graph is then topologically sorted to obtain the class integration test order, and the minimum total test stub complexity is output.
[0101] To obtain the class integration test order, perform topological sorting on the acyclic graph. This includes: finding nodes with an in-degree of 0 in the acyclic graph, outputting these nodes as the beginning of the test order, removing these nodes and their emanating edges from the acyclic graph, and repeating the above steps until all nodes are output. The final output node sequence is the class integration test order.
[0102] In one embodiment, the training process of the policy network includes the following steps: S301: Parse the source code of the sample software, generate a directed graph of samples, and determine multiple sample SCCs and the sub-states of each sample SCC based on the directed graph of samples.
[0103] S302, integrate the sub-states of all sample SCCs into a global state, and input the global state into the initial policy network to obtain the global action; the global action includes the action space of each sample SCC.
[0104] S303: Input the global state and global action into the initial value network to obtain the global action value.
[0105] The value network comprises a second shared encoder, a feature fusion layer, and multiple parallel and independent value heads, with one SCC corresponding to one value head. The global state and global action are input into the initial value network to obtain the global action value. This process includes: inputting the global state and global action into the initial value network; extracting the state features of the global state through the second shared encoder; and concatenating the state features and global action encodings in the feature fusion layer; inputting the concatenated features into each value head to obtain the value of each sample SCC; and summing the values of each SCC to obtain the global action value.
[0106] It should be noted that the structure of the second shared encoder is the same as that of the first shared encoder.
[0107] Each value head has different parameters; each value head includes a first sub-Q head and a second sub-Q head. For any sample SCC, the first sub-Q head of the sample SCC refines the local information of the sample SCC based on the concatenated features (e.g., removing the value features of edges in the sample SCC), compresses the dimensions, and filters key value signals to adapt to the individual characteristics of different SCCs (such as differences in the number of edges and cycles); the second sub-Q head calculates the value of the sample SCC based on the key value signals filtered by the first sub-Q head.
[0108] The value output by each value head is a scalar quantum Q value, representing the local value of the SCC under the current state-action pair.
[0109] Global Q-sum layer: Summing up the values of all sample SCCs to obtain the total value of the global state-action pair, i.e., the global action value.
[0110] S304: Execute the action for each sample SCC, update the sub-state of each sample SCC according to the state transition rule, and calculate the immediate reward for each sample SCC.
[0111] In one embodiment, calculating the instantaneous reward for each sample SCC includes the following steps: S401, for any sample SCC, determine the loop breaking reward based on the product of the number of loops broken by deleting dependent edges and the reward coefficient.
[0112] Optionally, removing the dependency edge breaks t Each loop yields a positive reward. , This is the reward coefficient.
[0113] S402, determine the test stub construction penalty based on the complexity of the test stubs introduced by deleting dependency edges and the cost of indirect dependencies. .
[0114] Among them, test pile construction penalty The complexity of direct test stubs and the additional cost of test stubs (indirect dependency cost) caused by related class dependencies were taken into account. This is the cost penalty coefficient. For class v To class w The test stub complexity of the dependency edges, The dependency edge to be deleted selected for the current decision action, i.e., from class v pointer class w The directed edge, In a directed graph, nodes w The set of all direct successor nodes (i.e., all classes that can be directly reached from w by an edge); In a directed graph, nodes u The set of all direct successor nodes; This means filtering out all edges. The middle node forming a directed triangular ring u ; For class u To class w The test stub complexity of the dependency edges; For class v To class u The test stub complexity of the dependency edges.
[0115] Specifically, delete edges This means that it is necessary to provide a class v Construct simulation class wThe test stakes will increase the complexity of the test stakes. On the other hand, deleting edges Meaning class v The final test order is superior to the class w This necessitates considering the impact of the testing order of these two classes on other classes. Assume there exists a third class. u ,if u rely v And was w Dependence, then, according to " v -> u -> w The test order is "" and no additional test stubs need to be built; however, if u rely w And was v If there is a dependency, then regardless of the final testing order of the three components, additional test stubs need to be built. Therefore, the smaller value of the test stub complexity in the two cases is taken as the indirect dependency cost.
[0116] S403, if all loops in sample SCC are destroyed after the dependent edges are removed, the reward calculation is complete.
[0117] When all loops of an SCC are destroyed ( (Change to 1), and give a one-time reward. , This is the completion coefficient.
[0118] S404, if the action is invalid, then determine the invalid action penalty.
[0119] When an invalid action is performed (such as deleting an edge that has already been deleted), a fixed negative reward of -ε is given, which is the penalty for the invalid action. ε is a positive number.
[0120] S405 determines the immediate reward based on the loop destruction reward, test pile construction penalty, completion reward, and invalid action penalty.
[0121] The sum of the loop destruction reward, test pile construction penalty, completion reward, and invalid action penalty is determined as the immediate reward.
[0122] A two-stage dynamic adjustment strategy is adopted: in the early stage (pre-T round), a larger λ and a smaller μ are used to encourage exploration to break through quickly; in the later stage (after T round), the λ and μ are switched to a smaller λ and a larger μ to focus on minimizing the cost of test piles.
[0123] Specifically, in the early stage of the policy network training process, the reward coefficient adopts a first threshold, and in the later stage of the policy network training process, the reward coefficient adopts a second threshold; the first threshold is greater than the second threshold; the early stage is the pre-preset number of training iterations in the policy network training process; the later stage is the training process after the early stage.
[0124] S305 stores the current state, action, reward, and next state as experience samples in the experience replay pool, and updates the parameters of the initial policy network and the initial value network according to the immediate reward, global action value, and target value, respectively.
[0125] The specific method of updating parameters is not the focus of this invention and will not be described in detail here. The traditional method of updating is sufficient.
[0126] S306, when the preset iteration termination condition is met, stop training, use the initial policy network obtained from training as the policy network, and use the initial value network obtained from training as the value network Critic.
[0127] After the policy network is trained, it learns the optimal policy. For a new software system to be tested, repeat steps S101-S103 to construct the ORD and identify loops. Then, using the trained SAC model (policy network), dependent edges are gradually removed in a deterministic manner (selecting the action with the highest probability) until all loops are broken. All removed edges, Deps*, form an acyclic graph. Topologically sorting this graph yields the final class integration test order, while also outputting the minimum total test stub complexity, OCplx*.
[0128] This application represents a systematic improvement to existing methods for generating class integration test sequences (CITOs). The core improvements are reflected in: Figure 2 The overall process shown and Figure 3 In the Actor-Critic network architecture shown below, the following is combined with... Figure 2 and Figure 3 The document details the structure, working principle, and positive effects of each improvement.
[0129] (I) Loop identification performance of pointer-guided stack-based backtracking algorithm (see...) Figure 2 (The "Pointer-Guided Stack Backtracking Algorithm for Identifying Loops and Dependencies" module) (1) Existing technical defects: Traditional recursive DFS cycle search requires independent calls starting from each vertex, resulting in a large number of repeated searches and a time complexity as high as O(n). 2 )~O(n 3 Furthermore, the recursion depth is limited by the system stack, making it prone to stack overflow when processing large-scale strongly connected components (SCCs).
[0130] (2) Structure of this application: In Figure 2After completing the Tarjan algorithm to identify SCCs, the program proceeds to the "Pointer-Guided Stack Backtracking Algorithm for Identifying Cycles and Dependencies" module. This algorithm maintains a successor pointer and an explicit stack for each vertex within an SCC, and completes the search for all cycles in one go through pointer advancement and stack backtracking.
[0131] (3) Working principle: Starting from any vertex, traverse along the successor pointer depth and push the vertex onto the explicit stack; when the successor of the current vertex is found to be in the stack, the sequence from the successor to the top of the stack forms a loop; the pointer records the position of the successor that has been processed for each vertex, and after processing all successors, backtrack to the previous vertex.
[0132] (4) Positive effects: The time complexity is reduced to O(n+e), which is 1 to 2 orders of magnitude more efficient than recursive DFS; the use of an explicit stack allocated on the heap to replace the function call stack completely eliminates the risk of stack overflow and stably handles the super-large SCC containing tens of thousands of vertices; all loops in the SCC can be found starting from a single vertex without repeated calls.
[0133] (II) The effect of hierarchical state and motion space design based on SCC decomposition (see Figure 2 (The process of "state, action, reward, network update cycle") (1) Existing technical limitations: Traditional reinforcement learning methods directly use the global ORD graph as the state space, which has a high dimensionality (total number of loops). M + Total number of dependent edges N In large-scale systems, this can easily lead to the "curse of dimensionality," making it difficult for neural networks to converge.
[0134] (2) Structure of this application: Figure 2 In the reinforcement learning training loop, each SCC is treated as an independent subproblem, constructing a hierarchical state space and action space. The global state S is... K It consists of 1 SCC substate, and each substate contains ( , , , Global action A is... K Each action is composed of individual movements.
[0135] (3) Working principle: There is no dependency between the SCCs after Tarjan decomposition, which satisfies the Markov property, and the substates can be updated independently; the neural network processes them simultaneously. K There are several substates, but because each substate is low-dimensional (typically...) m i + n i ≤100), the total number of parameters is much smaller than directly processing the global high-dimensional state; the action space is also decomposed, and the action dimension of each SCC is . ni+1 It also uses dynamic masks to block invalid actions in real time.
[0136] (4) Positive effects: The dimensionality is significantly reduced, making the original ( M + N )-dimensional global space decomposed into K With a low-dimensional subspace, the number of effective parameters is reduced by about 60% to 80%, and the training convergence speed is improved by 2 to 3 times; each step can select actions for all SCCs at the same time, and parallel decision-making greatly reduces the number of steps required to break the loop; it has strong scalability, and adding new classes or dependencies only affects the SCC in which they are located, without the need to retrain the global model.
[0137] (III) The effect of the dynamic action masking mechanism (see Figure 3 (The connection between "mask" and "Softmax") (1) Existing technical defects: The fixed action space contains a large number of invalid actions (deleted edges), and the agent needs to spend a lot of exploration steps to learn to avoid them, resulting in low training efficiency.
[0138] (2) Structure of this application: In Figure 3 In the process, after the independent action head outputs logits of the Actor network, it is compared with the dynamically generated mask vector. mask i Element-wise multiplication is performed, and the logits corresponding to invalid actions are set to negative infinity before being fed into Softmax normalization.
[0139] (3) Working principle: The mask is based on the current sub-state and Real-time generation: 1 corresponds to a valid edge or an empty action, and 0 corresponds to a deleted edge; after the multiplication operation, the Softmax output probability of an invalid action is strictly 0, and the agent can only sample from valid actions.
[0140] (4) Positive effects: Accelerates convergence by about 30%, the agent does not need to learn "which actions are not available" through trial and error, and every decision is an effective action; stabilizes the policy gradient, avoids the increase in gradient variance caused by occasional invalid actions, and makes the training curve smoother.
[0141] (iv) The effect of the two-stage dynamic reward function (see Figure 2 (The loop of "calculating reward R" and "network update") (1) Existing technical defects: A single fixed reward weight is difficult to balance the two objectives of "rapid destruction" and "minimizing cost", and is prone to getting trapped in local optima.
[0142] (2) Structure of this application: reward function ,in Includes loop destruction rewards Test pile construction penalty and completion rewards And penalty for ineffective movements -ε. Dynamically adjusted during training. and Early stage high ,Low Encourage exploration of disruption; low later stages ,high Focus on cost optimization.
[0143] (3) Working principle: breaking through in the early stage t A high reward is given for each loop, which incentivizes the agent to try to destroy the edges of multiple loops at the same time, even if the cost is slightly higher, thus quickly reducing the number of loops. When there are few remaining loops in the later stage, the weight of the cost penalty is reduced, guiding the agent to choose the edge with the lowest cost to complete the process.
[0144] (4) Positive effects: Compared with the fixed weight method, the total test pile complexity is reduced by an average of 15%~22%; the completion reward is proportional to the SCC size, and the model naturally prioritizes large SCCs, which is in line with the principle of prioritizing the testing of core modules in engineering.
[0145] (V) Performance of the SAC-based variable-length input Actor-Critic network architecture (see...) Figure 3 ) (1) Existing technology defects: the number of loops in different SCCs and number of dependent edges The results vary, and directly concatenating them as network input will lead to indeterminate dimensions, making batch training impossible; forced padding will result in wasted computation and information distortion.
[0146] (2) Structure of this application: In Figure 3 The bottom is elongated. and The vector first enters the embedding layer: after 1×1 convolution and global average pooling, it is mapped to a fixed-length feature vector. and Subsequently with , By splicing them together, sub-state features with fixed dimensions are formed.
[0147] (3) Working principle: 1×1 convolutional linear transformation captures the correlation between loops or dependent edges (e.g., multiple loops share the same edge); global average pooling compresses the variable-length intermediate feature map into a fixed dimension, preserving the overall distribution information; fixed-length embedding vectors are input into the subsequent shared encoder, supporting batch training.
[0148] (4) Positive effects: It supports SCC of any size without padding or truncation, and directly processes the original variable-length input with complete information; the same set of convolutional kernels can be applied to inputs of different lengths, and the model can generalize to SCC sizes not seen in training; global average pooling is parameterless, the number of convolutional kernels is small (typically 32), the number of parameters increases by less than 5%, but the training speed is improved by about 25% (avoiding redundant calculations caused by padding).
[0149] (5) The effect of the parallel independent head structure of Actor and Critic (see Figure 3 (Upper part): After the Actor shares the encoder, K Each parallel independent action head outputs a probability distribution for each SCC, enabling parallel decision-making; the Critic is processed through a shared encoder and a feature fusion layer, and then... K Each parallel independent sub-Q head outputs the sub-Q value of each SCC, and finally sums them to obtain the global Q value.
[0150] Positive effects: Decoupled learning, the policy and value of each SCC are optimized independently, avoiding interference between different SCCs; Parallel computation, all independent heads can be computed in parallel on GPUs, resulting in high training efficiency; Scalable, adding a new SCC only requires adding the corresponding independent head, without modifying the main network structure.
[0151] comprehensive Figure 2 The overall process shown is Figure 3 The network architecture shown in this application represents a targeted improvement in key aspects such as loop identification, state-action space modeling, exploration-exploitation balance, and variable-length input processing. Experiments demonstrate that, compared to existing methods based on graph theory, genetic algorithms, or traditional reinforcement learning, this invention can reduce the cost of test stub construction by 20%–35%, improve training convergence speed by 2–3 times, and stably handle large-scale object-oriented systems (such as embodied intelligent software) containing thousands of classes. The structure and collaborative working principles of each improved component are described in [the document / document / etc.]. Figure 2 and Figure 3 It is clearly shown in the image.
[0152] The execution subject of the methods provided in this specification can be a server, which can be a server set up on a business platform, or a device such as a desktop computer or laptop computer that can execute the solutions in this specification.
[0153] When applying the software-oriented class integration test sequence generation method provided in this manual, it is not necessary to follow the... Figure 1 The steps shown are executed in sequence. The specific execution order of each step can be determined as needed, and this manual does not impose any restrictions on it.
[0154] The above describes a method for generating a software-oriented class integration test sequence according to one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding apparatus for generating a software-oriented class integration test sequence, which includes: The parsing and search module is used to extract all classes and inter-class dependencies in the software under test, and construct a directed graph by treating all classes as vertices and inter-class dependencies as directed edges; it identifies all strongly connected components (SCCs) in the directed graph; strongly connected components are used to represent cyclic dependency clusters of classes in the software under test. The loop identification module is used to perform loop search for each SCC to obtain all loops in the SCC and the set of dependencies involved therein; The state construction module is used to construct the sub-state of each SCC based on all loops, dependency sets, and test stub complexity of each dependency edge. The sub-state represents the coverage of loops, the existence status of dependencies, and test stub complexity information in vector form. The loop removal module is used to input the sub-states of all SCCs into the pre-trained policy network and iteratively generate the action space to indicate the dependent edges to be removed in each SCC until the sub-states of all SCCs indicate that all their loops have been completely destroyed. During training, the policy network determines the reward based on the test stub cost of deleting dependent edges and the contribution of dependent edges to the overall destruction of loops. After all the loops of all SCCs in the directed graph are completely destroyed, an acyclic graph is formed. The sorting module is used to perform topological sorting on acyclic graphs to obtain the class integration test order.
[0155] Specific limitations regarding the software-oriented class integration test sequence generation device can be found in the limitations of the software-oriented class integration test sequence generation method described above, and will not be repeated here. Each module in the aforementioned software-oriented class integration test sequence generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0156] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 Provides a method for generating the order of class integration tests for software.
[0157] This instruction manual also provides Figure 4 The schematic diagram of the computer device shown is as follows: Figure 4As shown, at the hardware level, this computer device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then executes it to achieve the above. Figure 1 Provides a method for generating the order of class integration tests for software.
[0158] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0159] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A method for generating the order of software integration tests, characterized in that, include: Extract all classes and their dependencies in the software under test, and construct a directed graph by using all classes as vertices and the dependencies between classes as directed edges. Identify all strongly connected components (SCCs) in the directed graph; strongly connected components are used to characterize cyclic dependency clusters of classes in the software under test. Perform a loop search on each SCC to obtain all loops in the SCC and the set of dependencies involved therein; The dependency set includes all dependent edges in the loop; Based on all loops, dependency sets, and test stub complexity of each dependency edge in each SCC, a substate of each SCC is constructed; the substate represents the coverage of loops, the existence state of dependency edges, and test stub complexity information in vector form. The sub-states of all SCCs are input into a pre-trained policy network, which iteratively generates an action space to indicate the dependent edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed. During training, the policy network determines the reward based on the test stub cost of deleting dependent edges and the contribution of dependent edges to the overall destruction of loops. After all loops of all SCCs in the directed graph are completely destroyed, an acyclic graph is formed. Perform topological sorting on the acyclic graph to obtain the class integration test order.
2. The method according to claim 1, characterized in that, Perform a loop search on each SCC to obtain all loops in the SCC and the set of their dependencies, including: For each SCC, initialize the successor list and backtrack pointer for each vertex in the SCC, and create an empty stack; the successor list stores all direct successor vertices of the vertex; the pointer represents an integer index pointing to the position in the successor list; Starting from any vertex, push the vertex onto the stack, and perform a depth-first traversal along the successor pointer of that vertex. After traversing a successor vertex, increment the pointer by 1. When it is detected that the successor vertex of the current vertex is already in the stack, extract all vertices from the successor vertex to the top of the stack as a loop, and record the dependent edges contained in the loop. Once all successor vertices of any given vertex have been processed, pop that vertex from the stack and reset its pointer to 0, backtrack to the previous vertex, and continue processing its unprocessed branches. Once all vertices have been traversed, output all loops in the strongly connected components and the set of their dependencies.
3. The method according to claim 1, characterized in that, The sub-state includes the loop existence vector, the remaining dependency vector, the current total test stub complexity, and the completion flag; The loop existence vector indicates whether each loop in the corresponding SCC is still intact; The remaining dependency vector indicates whether each dependency edge in the corresponding SCC still exists; The current total test stub complexity represents the sum of the test stub complexities of the currently deleted edges; The completion indicator signifies whether all loops of the SCC have been completely destroyed.
4. The method according to claim 3, characterized in that, The sub-states of all SCCs are input into a pre-trained policy network to iteratively generate action spaces that indicate the dependent edges to be deleted in each SCC, until the sub-states of all SCCs indicate that all their loops have been completely destroyed, including: All sub-states of SCC are input into a policy network trained through reinforcement learning to generate an action space; the action space includes the action probability distribution of SCC. For any SCC, a binary mask vector is generated based on the remaining dependency vector and completion flag in the substate. The length of the binary mask vector is equal to the action space dimension of the SCC. The index of the dependency edge that has not been deleted and the corresponding position of the empty action are set to 1, and the corresponding position of the index of the deleted dependency edge is set to 0. The action probability distribution of the SCC is multiplied element-wise with the binary mask vector, and then the processed action probability distribution is normalized by the Softmax function to obtain the action to be executed by the SCC; the action to be executed by the SCC represents the dependency edge to be deleted. Update the sub-states according to the actions to be performed, and continue to generate new action spaces based on the updated sub-states until all SCC sub-states indicate that all their loops have been completely destroyed.
5. The method according to claim 4, characterized in that, The policy network includes a first shared encoder and multiple parallel independent action heads, with one SCC corresponding to one independent action head. Each independent action head includes a first action head and a second action head. The sub-states of all SCCs are input into the policy network trained through reinforcement learning to generate the action space, including: All SCC sub-states are integrated into a global state input to the first shared encoder, and the common features of all SCC sub-states are extracted through the first shared encoder. For any SCC, the general features are input into the first action head of the SCC. The features of the SCC are refined through the first action head. The refined features are then input into the second action head to obtain the action probability distribution. The action probability distribution is used as the action space of the SCC.
6. The method according to claim 4, characterized in that, The method further includes: During the sub-state update process, the loop existence vector and residual dependency vector with varying lengths are mapped to fixed lengths through the embedding layer; the embedding layer includes concatenated convolutional layers and global average pooling layers.
7. The method according to claim 4, characterized in that, The training process of the policy network includes: The source code of the sample software is analyzed to generate a sample directed graph. Based on the sample directed graph, multiple sample SCCs and the sub-states of each sample SCC are determined. The sub-states of all sample SCCs are integrated into a global state, and the global state is input into the initial policy network to obtain the global action; the global action includes the action space of each sample SCC. The global state and global actions are input into the initial value network to obtain the global action value; Execute the action for each sample SCC separately, update the sub-state of each sample SCC according to the state transition rule, and calculate the immediate reward for each sample SCC. The current state, action, reward, and next state are stored as experience samples in the experience replay pool, and the parameters of the initial policy network and the initial value network are updated according to the immediate reward, global action value, and target value, respectively. When the preset iteration termination condition is met, training stops, and the initial policy network obtained from training is used as the policy network, and the initial value network obtained from training is used as the value network.
8. The method according to claim 7, characterized in that, The value network consists of a second shared encoder, a feature fusion layer, and multiple independent value heads, with one SCC corresponding to one value head; The global state and global action are input into the initial value network to obtain the global action value, including: The global state and global action are input into the initial value network, the state features of the global state are extracted by the second shared encoder, and the state features and global action are encoded and concatenated in the feature fusion layer. The concatenated features are input into each value head to obtain the value of each sample SCC. Sum the values of each SCC to obtain the global action value.
9. The method according to claim 7, characterized in that, Calculate the immediate reward for each sample SCC, including: For any sample SCC, the loop breaking reward is determined by multiplying the number of loops broken by deleting dependent edges by the reward coefficient. The test stub construction penalty is determined based on the complexity of the test stubs introduced by deleting dependency edges and the cost of indirect dependencies. If all loops in sample SCC are destroyed after the dependent edges are removed, the reward calculation is complete. If the action is invalid, then an invalid action penalty will be determined; The immediate reward is determined based on the loop destruction reward, test pile construction penalty, completion reward, and invalid action penalty.
10. The method according to claim 9, characterized in that, In the early stages of policy network training, a first threshold is used for the reward coefficient, and in the later stages of policy network training, a second threshold is used for the reward coefficient; the first threshold is greater than the second threshold. The early stage is the pre-set number of iterations during the policy network training process; The later stage is the training process following the earlier stage.