Class integration test sequence generation method fusing reinforcement learning and simulated annealing strategy
By integrating reinforcement learning and simulated annealing strategies, the optimal class integration test sequence for object-oriented programs is generated, which solves the problem of high test pile complexity caused by complex inter-class dependencies and improves testing efficiency and stability.
Patent Information
- Application Number
- CN202410792370.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-10-15
AI Technical Summary
The complex dependencies between classes in object-oriented programs make it difficult for traditional integration testing methods to generate reasonable class integration test sequences, which increases the complexity and cost of test stubs.
Using a method that integrates reinforcement learning and simulated annealing strategies, we obtain inter-class coupling information through static analysis, construct a test cost matrix, model inter-class relationships as an agent environment, and use the Sarsa algorithm to train agents to generate optimal class integration test sequences. .
It effectively reduces the overall test stub complexity of class integration testing, improves test efficiency and solution stability, avoids local optimal solutions, and reduces test stub costs.
Smart Images

Figure BDA0004900470160000031 
Figure BDA0004900470160000032 
Figure BDA0004900470160000061
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a method for generating a class integration test sequence by integrating reinforcement learning and simulated annealing strategies. Background Art
[0002] The software testing phase includes five parts, namely unit testing, integration testing, system testing, verification and validation, and regression testing; among them, integration testing is a key step in the software testing phase, ensuring that each module and subsystem can run accurately and stably according to the expected goals.
[0003] Common integration testing methods include bottom-up, top-down, and sandwich methods. These testing methods are consistent with the characteristics of process-oriented programs and can accurately and efficiently complete the integration testing tasks of process-oriented programs. However, for object-oriented programs, due to the lack of obvious hierarchical structure in the system and the complex calling relationships between classes, testers cannot directly use the above methods for integration testing; therefore, in view of the inter-class dependency characteristics of object-oriented programs, it is necessary to design a reasonable class integration testing strategy to determine the order in which each class in the system is tested.
[0004] In the process of integration testing, if the class being tested requires services from other classes and other classes have not yet been integrated, it is necessary to build test stubs to simulate the corresponding methods or properties to provide the services required by the class being tested. Since various inter-class dependencies are common in object-oriented programs, it is inevitable to build various test stubs, which adds additional costs. How to perform integration testing on programs at a lower test stub cost to output reliable software products is a key issue that researchers and developers need to solve. The test stub complexity is used to measure the cost of building each test stub. The complexity of the test stubs required to build different test stubs is different when performing integration testing in different inter-class test sequences. A reasonable class integration test sequence can effectively reduce the complexity of the test stubs and avoid unnecessary test stub costs. It can be seen that it is of great significance to propose a reasonable class integration test sequence generation technology for integration testing of object-oriented programs. Summary of the invention
[0005] In view of the problems existing in the above-mentioned prior art, the present invention provides a class integration test sequence generation method integrating reinforcement learning and simulated annealing strategies. Firstly, a static analysis is performed on the program to obtain inter-class coupling information, and the attribute complexity, method complexity and test pile complexity are calculated; secondly, a reinforcement learning scenario is designed, a test cost matrix is constructed, and the relationship between classes is modeled as an environment for interaction with an intelligent agent; then, an action exploration strategy is designed, and an exploration strategy based on simulated annealing is adopted to select the actions of the intelligent agent; finally, the intelligent agent is trained using the Sarsa algorithm, and the optimal strategy is learned through continuous interaction between the intelligent agent and the environment. When the learning process is completed, an optimal class integration test sequence is obtained.
[0006] The problem of "in the existing methods for solving the problem of generating integration test sequences, the traditional ε-greedy strategy is highly blind in exploration, which easily causes the algorithm to fall into the local optimal solution, and the stability of the generated solution is poor when solving the problem, resulting in a high cost of test piles" is solved, which improves the efficiency of integration testing while ensuring high availability.
[0007] In order to achieve the above object, the technical solution adopted by the present invention is: a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy, the method comprising the following steps:
[0008] (1) Static analysis of programs: Use the Soot framework to perform static analysis on programs, obtain member variable information, member method information, and attribute coupling and method coupling between classes, calculate the inter-class coupling information, namely, attribute complexity and method complexity, and calculate the cost required to build test stubs for inter-class relationships based on the attribute complexity and method complexity values, namely, the test stub complexity;
[0009] (2) Design reinforcement learning scenarios: Obtain inter-class coupling information of the program based on the static analysis module, construct a test cost matrix, and model the relationship between classes as an environment for interaction with the agent;
[0010] (3) Design action exploration strategy: Use an exploration strategy based on simulated annealing to select the agent's actions, set the temperature update function and related parameters in the strategy, including state factor, initial temperature, minimum temperature, and cooling rate;
[0011] (4) Training the agent: Use the Sarsa algorithm to train the agent;
[0012] (5) Generate class integration test sequence: The optimal strategy is learned through continuous interaction between the intelligent agent and the environment. When the learning process is completed, an optimal class integration test sequence is obtained.
[0013] Furthermore, the specific method for calculating the attribute complexity, method complexity, and test pile complexity in step (1) is as follows:
[0014] 1) Calculation attribute complexity
[0015] In object-oriented design, if class i and class j have a dependency relationship, and the method of class i calls the attributes of class j, such as method parameters, method return values, or member variables, then it can be considered that there is attribute coupling between class i and class j; attribute complexity refers to the sum of the number of member variables, method parameter types, and method return values of class j called by class i, recorded as A(i,j);
[0016] 2) Calculation method complexity
[0017] If class i calls a method in class j, it can be considered that there is method coupling between class i and class j; method complexity is defined as the number of methods called by class i in class j, denoted as M(i,j);
[0018] 3) Calculate the complexity of the test pile
[0019] When class i depends on class j and needs to be tested before class j, a test stub Stub(i,j) needs to be built for class i to simulate the methods and properties provided by class j. The calculation formula for the test stub complexity is as follows:
[0020]
[0021] Furthermore, the step (2) constructs a test cost matrix:
[0022] For the test cost matrix C, let C = [C iu ] N*N , where N refers to the number of classes contained in the program; the testing cost between class i and class u is expressed as C iu (i, u = 1, 2, ..., N and i ≠ j), if class i does not depend on class u, C iu The value of is 0; otherwise, if class i depends on class u, the test cost C iu The value of is determined by the test pile complexity SCplx(i, j) between the two; the calculation formula is as follows:
[0023]
[0024] Furthermore, in step (2), the relationship between classes is modeled as an environment for the agent to interact with: this process includes the design of elements such as the agent's action space, state space, and reward function, which provides the necessary foundation for the agent to learn how to interact with these inter-class relationships.
[0025] Furthermore, in the exploration strategy based on simulated annealing in step (3), a linear cooling function is used to update the temperature, and the temperature T is gradually reduced according to a linear law until the set stop condition is reached; specifically, as shown in the formula below, wherein T(k) represents the temperature of the kth iteration, q is a cooling parameter, and the range of q is generally between 0 and 1;
[0026] T(k+1)=q×T(k).
[0027] Furthermore, the state factor in the action value setting strategy of the Sarsa algorithm is updated, and the setting parameters include the initial temperature, the minimum temperature and the cooling rate parameter. For the state factor ε, let ε = Q(s t , A t )-Q(s t , A.P. t ), where t is the current temperature, A t For t Random action in state, AP t For t The action with the maximum Q value under the state; the specific process of the exploration strategy based on simulated annealing is as follows: First, randomly initialize action action = A t , get the action with the maximum Q value action_max = AP t ; Secondly, in s t Under the state, the disturbance value δ of action selection and the disturbance limit value of action selection If δ<P, the random action A t As the current action, otherwise take the best action AP t is the current action; finally, determine whether it has reached the termination state. If it is "yes", the action exploration ends; if it is "no", the search operation continues.
[0028] Furthermore, in step (4), the Sarsa algorithm updates the value function once in each strategy step. Before updating the value function, it only needs to know the state of the previous step (s), the action of the previous step (a), the reward value to be obtained (r), the current state (s′), and the action to be performed (a′). The iterative update formula is as follows:
[0029] Q(s,a)=Q(s,a)+α(r+γQ(s',a')-Q(s,a)).
[0030] Furthermore, the specific steps of step (4) are as follows: first, the parameters of the Sarsa algorithm are set, including the number of training rounds, the learning rate, and the discount rate; then, the Sarsa algorithm is used to guide the agent to interact with the environment and continuously optimize the learning strategy of the agent.
[0031] Furthermore, the step (5) comprises the following specific steps:
[0032] Step (5-1): According to the exploration strategy based on simulated annealing, select appropriate classes to add to the class integration test sequence;
[0033] Step (5-2): Continuously optimize the learning strategy of the agent based on the reward value of the feedback;
[0034] Step (5-3): Check whether the class integration test sequence has been generated. If so, end; otherwise, jump to steps (5-1)-(5-2) to continue execution.
[0035] Furthermore, in step (5), when solving the class integration test sequence generation problem, if there are n classes in the program to be tested, the action space A stores n actions, and there are n possibilities for the first action selected by the agent, that is, there are n possible states; at the same time, there are n possibilities for transitioning from the first state to the second state, which means that each time there are n possibilities to transition to the next state until the transition to the final state; the state space S has at most (nn+1-1) / (n-1) states; in a path composed of actions, if the path does not have repeated actions and contains n actions, it constitutes a possible action sequence, that is, a candidate class integration test sequence sought.
[0036] The beneficial effect of the present invention is that it solves the problem that "in the existing methods for solving the problem of generating class integration test sequences, the traditional ε-greedy strategy exploration is highly blind, which easily causes the algorithm to fall into a local optimal solution, and the stability of the generated solution is poor when solving the problem, resulting in a high cost of the test pile". The present invention can effectively reduce the overall test pile complexity of the class integration test sequence, and the stability of generating solutions multiple times on different programs to be tested is also improved to a certain extent, thereby improving the efficiency of software testing and ultimately better controlling the quality of software products. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 is a flow chart of the present invention;
[0038] Figure 2 It is a flowchart of the static analysis program;
[0039] Figure 3 Flowchart of the exploration strategy based on simulated annealing;
[0040] Figure 4 Flowchart for training an agent. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present invention more clear, the present invention is further described in detail below through the accompanying drawings and embodiments. However, it should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the scope of the present invention.
[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which the present invention belongs. The terms used in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0043] like Figure 1 As shown, a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy comprises the following steps:
[0044] (1) Static analysis programs, such as Figure 2 As shown: the program is statically analyzed through the Soot framework to obtain member variable information, member method information, and attribute coupling and method coupling between classes of each type, and calculate the inter-class coupling information, namely, attribute complexity and method complexity. According to the attribute complexity and method complexity values, the cost required to build a test stub for the inter-class relationship is calculated, namely, the test stub complexity. The test stub complexity is calculated in a linearly weighted manner, combining the attribute complexity and the method complexity, as the cost required to build a test stub for the inter-class relationship.
[0045] The specific methods for calculating attribute complexity, method complexity, and test pile complexity are as follows:
[0046] 1) Calculation attribute complexity
[0047] In object-oriented design, if class i and class j have a dependency relationship, and the method of class i calls the attributes of class j, such as method parameters, method return values, or member variables, then it can be considered that there is attribute coupling between class i and class j; attribute complexity refers to the sum of the number of member variables, method parameter types, and method return values of class j called by class i, recorded as A(i,j);
[0048] 2) Calculation method complexity
[0049] If class i calls a method in class j, it can be considered that there is method coupling between class i and class j; method complexity is defined as the number of methods called by class i in class j, denoted as M(i,j);
[0050] 3) Calculate the complexity of the test pile
[0051] When class i depends on class j and needs to be tested before class j, a test stub Stub(i,j) needs to be built for class i to simulate the methods and properties provided by class j. The calculation formula for the test stub complexity is as follows:
[0052]
[0053] (2) Design reinforcement learning scenarios: Obtain inter-class coupling information of the program based on the static analysis module, construct a test cost matrix, and model the relationship between classes as an environment for interaction with the agent;
[0054] Construct a test cost matrix based on inter-class coupling information:
[0055] For the test cost matrix C, let C = [C iu ] N*N , where N refers to the number of classes contained in the program; the testing cost between class i and class u is expressed as C iu (i, u = 1, 2, ..., N and i ≠ j), if class i does not depend on class u, C iu The value of is 0; otherwise, if class i depends on class u, the test cost C iu The value of is determined by the test pile complexity SCplx(i, j) between the two; the calculation formula is as follows:
[0056]
[0057] The relationship between classes is modeled as an environment for the agent to interact with. This process includes the design of elements such as the agent's action space, state space, and reward function. It provides the necessary foundation for the agent to learn how to interact with these inter-class relationships.
[0058] (3) Design action exploration strategy: Use an exploration strategy based on simulated annealing to select the agent's actions, set the temperature update function and related parameters in the strategy, including state factor, initial temperature, minimum temperature, and cooling rate;
[0059] The temperature is updated using a linear cooling function, and the temperature T is gradually reduced according to a linear rule until the set stop condition is reached; specifically, as shown in the formula below, where T(k) represents the temperature of the kth iteration, and q is a cooling parameter, and the range of q is generally between 0 and 1;
[0060] T(k+1)=q×T(k);
[0061] Combined with the action value of Sarsa algorithm, the state factor in the setting strategy is updated. The setting parameters include initial temperature, minimum temperature and cooling rate parameters, such as Figure 3 As shown, for the state factor ε, let ε =
[0062] Q(s t , A t )-Q(s t , A.P. t ), where t is the current temperature, A t For t Random action in state, AP t For t The action with the maximum Q value under the state; the specific process of the exploration strategy based on simulated annealing is as follows: First, randomly initialize action action = A t , obtain the action with the maximum Q value action_max = AP t ; Secondly, in s t Under the state, the disturbance value δ of action selection and the disturbance limit value of action selection
[0063] If δ<P, the random action A t As the current action, otherwise take the best action AP t is the current action; finally, determine whether it has reached the termination state. If it is "yes", the action exploration ends; if it is "no", the search operation continues.
[0064] (4) Training the agent: Use the Sarsa algorithm to train the agent;
[0065] like Figure 4 As shown, first, the parameters of the Sarsa algorithm are set, including the number of training rounds, learning rate, and discount rate. Then, the Sarsa algorithm is used to guide the agent to interact with the environment and continuously optimize the learning strategy of the agent.
[0066] The Sarsa algorithm updates the value function once in each strategy step. Before updating the value function, it only needs to know the state of the previous step (s), the action of the previous step (a), the reward value to be obtained (r), the current state (s′), and the action to be performed (a′). The iterative update formula is as follows:
[0067] Q(s,a)=Q(s,a)+α(r+γQ(s',a')-Q(s,a)).
[0068] (5) Generate class integration test sequence: The optimal strategy is learned through continuous interaction between the agent and the environment. When the learning process is completed, an optimal class integration test sequence is obtained. The specific steps are as follows:
[0069] Step (5-1): According to the exploration strategy based on simulated annealing, select appropriate classes to add to the class integration test sequence;
[0070] Step (5-2): Continuously optimize the learning strategy of the agent based on the reward value of the feedback;
[0071] Step (5-3): Check whether the class integration test sequence has been generated. If so, end; otherwise, jump to steps (5-1)-(5-2) to continue execution.
[0072] In the step (5), when solving the class integration test sequence generation problem, if there are n classes in the program to be tested, the action space A stores n actions, and there are n possibilities for the first action selected by the agent, that is, there are n possible states; at the same time, there are n possibilities for transitioning from the first state to the second state, which means that each time there are n possibilities to transition to the next state until the transition to the final state; the state space S has at most (nn+1-1) / (n-1) states; in a path composed of actions, if the path does not have repeated actions and contains n actions, it constitutes a possible action sequence, that is, a candidate class integration test sequence required.
[0073] The following is an experimental analysis using this method:
[0074] Experiments were conducted on three systems: elevator, daisy, and email-spl. The detailed information of these three systems is shown in Table 1:
[0075] Table 1 Experimental subject information
[0076]
[0077] Table 2 Overall test pile complexity comparison
[0078]
[0079] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modification, equivalent substitution or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for generating quasi-integrated test sequences by integrating reinforcement learning and simulated annealing strategies. Features: The method comprises the following steps: (1) Static analysis of programs: Use the Soot framework to perform static analysis on programs, obtain member variable information, member method information, and attribute coupling and method coupling between classes, calculate the inter-class coupling information, namely, attribute complexity and method complexity, and calculate the cost required to build test stubs for inter-class relationships based on the attribute complexity and method complexity values, namely, the test stub complexity; (2) Design reinforcement learning scenarios: Obtain inter-class coupling information of the program based on the static analysis module, construct a test cost matrix, and model the relationship between classes as an environment for interaction with the agent; (3) Design action exploration strategy: Use an exploration strategy based on simulated annealing to select the agent's actions, set the temperature update function and related parameters in the strategy, including state factor, initial temperature, minimum temperature, and cooling rate; (4) Training the agent: Using the Sarsa algorithm to train the agent; (5) Generate class integration test sequence: The optimal strategy is learned through continuous interaction between the intelligent agent and the environment. When the learning process is completed, an optimal class integration test sequence is obtained.
2. According to claim 1, a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy, Features: The specific method for calculating the attribute complexity, method complexity, and test pile complexity in step (1) is as follows: 1) Calculation attribute complexity In object-oriented design, if class i and class j have a dependency relationship, and the method of class i calls the attributes of class j, such as method parameters, method return values, or member variables, then it can be considered that there is attribute coupling between class i and class j; attribute complexity refers to the sum of the number of member variables, method parameter types, and method return values of class j called by class i, recorded as A(i,j); 2) Calculation method complexity If class i calls a method in class j, it can be considered that there is method coupling between class i and class j; method complexity is defined as the number of methods called by class i in class j, denoted as M(i,j); 3) Calculate the complexity of the test pile When class i depends on class j and needs to be tested before class j, a test stub Stub(i,j) needs to be built for class i to simulate the methods and properties provided by class j. The calculation formula for the test stub complexity is as follows:
3. According to claim 1, a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy, It is characterized in that The step (2) constructs a test cost matrix: For the test cost matrix C, let C = [C iu ] N*N , where N refers to the number of classes contained in the program; the testing cost between class i and class u is expressed as C iu (i, u = 1, 2, ..., N and i ≠ j), if class i does not depend on class u, C iu The value of is 0; otherwise, if class i depends on class u, the test cost C iu The value of is determined by the test pile complexity SCplx(i, j) between the two; the calculation formula is as follows:
4. According to claim 1, a method for generating a class integrated test sequence integrating reinforcement learning and simulated annealing strategy, It is characterized in that In step (2), the relationship between classes is modeled as an environment for the agent to interact with: this process includes the design of elements such as the agent's action space, state space, and reward function, which provides the necessary foundation for the agent to learn how to interact with these inter-class relationships.
5. According to claim 1, a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy, It is characterized in that In the step (3), in the exploration strategy based on simulated annealing, a linear cooling function is used to update the temperature, and the temperature T is gradually reduced according to a linear law until the set stop condition is reached; specifically, as shown in the formula below, wherein T(k) represents the temperature of the kth iteration, q is a cooling parameter, and the range of q is generally between 0 and 1; T(k+1)=q×T(k).
6. A method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy according to claim 5, It is characterized in that Combined with the action value of Sarsa algorithm, the state factor in the setting strategy is updated. The setting parameters include initial temperature, minimum temperature and cooling rate parameters. For the state factor ε, let ε = Q(s t , A t )-Q(s t , A.P. t ), where t is the current temperature, A t For t Random action in state, AP t For t The action with the maximum Q value under the state; the specific process of the exploration strategy based on simulated annealing is as follows: First, randomly initialize action action = A t , obtain the action with the maximum Q value action_max = AP t ; Secondly, in s t Under the state, the disturbance value δ of action selection and the disturbance limit value of action selection If δ<P, the random action A t As the current action, otherwise take the best action AP t is the current action; finally, determine whether it has reached the termination state. If it is "yes", the action exploration ends; if it is "no", the search operation continues.
7. The method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy according to claim 1, It is characterized in that In step (4), the Sarsa algorithm updates the value function once in each strategy step. Before updating the value function, it only needs to know the state (s) of the previous step, the action (a) of the previous step, the reward value (r), the current state (s′), and the action to be performed (a′). The iterative update formula is as follows: Q(s,a)=Q(s,a)+α(r+γQ(s',a')-Q(s,a)).
8. According to claim 1, a method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy, It is characterized in that The specific steps of step (4) are as follows: first, the parameters of the Sarsa algorithm are set, including the number of training rounds, the learning rate, and the discount rate; then, the Sarsa algorithm is used to guide the intelligent agent to interact with the environment and continuously optimize the learning strategy of the intelligent agent.
9. The method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy according to claim 1, It is characterized in that The specific steps of step (5) are as follows: Step (5-1): According to the exploration strategy based on simulated annealing, select appropriate classes to add to the class integration test sequence; Step (5-2): Continuously optimize the learning strategy of the agent based on the reward value of the feedback; Step (5-3): Check whether the class integration test sequence has been generated. If so, end; Otherwise, jump to steps (5-1)-(5-2) to continue execution.
10. A method for generating a class integration test sequence integrating reinforcement learning and simulated annealing strategy according to claim 9, It is characterized in that In the step (5), when solving the class integration test sequence generation problem, if there are n classes in the program to be tested, the action space A stores n actions, and there are n possibilities for the first action selected by the agent, that is, there are n possible states; at the same time, there are n possibilities for transitioning from the first state to the second state, which means that each time there are n possibilities to transition to the next state until the transition to the final state; the state space S has at most (nn+1-1) / (n-1) states; in a path composed of actions, if the path does not have repeated actions and contains n actions, it constitutes a possible action sequence, that is, a candidate class integration test sequence required.
