Program testing method and device based on SARSA algorithm
By applying the SARSA algorithm in the Windows application automation test, the problem of insufficient test coverage, high maintenance costs, low efficiency, and difficulty in processing difficulty in traditional testing methods have been solved, and more efficient and intelligent test solutions have been achieved.
Patent Information
- Application Number
- CN202411592035.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-01-21
AI Technical Summary
Traditional Windows application automation testing faces problems such as insufficient test coverage, high maintenance costs for test scripts, inefficient testing efficiency and difficulty in dealing with complex user interactions.
Adopting a program test method based on the SARSA algorithm, the environment modeling is used to treat the program. The abstract GUI element is the status space and the user operation space, define the reward function, initialize the SARSA algorithm parameter, automatically executes the test process and calculates the test index.
It improves the automation and accuracy of testing, reduces testing costs, enhances the adaptability and efficiency of testing, and can more comprehensively cover various functions and statuses of the application.
Smart Images

Figure CN119336646A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software testing technology, and in particular to a program testing method and apparatus based on the SARSA algorithm. Background Technology
[0002] As one of the world's most popular operating systems, Windows applications are crucial for ensuring software quality and user satisfaction through testing. However, with the increasing complexity of Windows applications, traditional automated testing methods face numerous challenges, such as high test case maintenance costs, insufficient test coverage, and difficulty adapting to dynamic changes in applications.
[0003] Existing automated testing solutions still face many challenges when dealing with complex Windows applications, such as: insufficient test coverage, easily overlooking key functions and potential problems; high test script maintenance costs: with application updates and iterations, test scripts need to be frequently modified to adapt to new features and interface changes; low testing efficiency: manual execution of tests is time-consuming, and repetitive work can easily lead to tester fatigue and distraction; difficulty in handling complex user interactions: Windows applications often contain complex user interactions, such as multi-window operations and dynamic content loading, which are difficult for manually written test scripts to effectively handle. Summary of the Invention
[0004] This invention provides a program testing method and apparatus based on the SARSA algorithm to overcome the shortcomings of the prior art.
[0005] The first aspect of this invention provides a program testing method based on the SARSA algorithm, comprising: S1: Perform environmental modeling on the program under test to obtain the problem space; S2: Initialize the SARSA algorithm parameters and obtain the test algorithm; S3: Execute the problem space using the test algorithm to obtain the execution results; S4: Calculate the test metrics based on the execution results to obtain the test results.
[0006] According to the program testing method based on the SARSA algorithm provided by the present invention, step S1 further includes: S11: Abstract the GUI elements of the program under test into a state space; abstract the user operations of the program under test into an action space; S12: Define a reward function, and output the state space, the action space, and the reward function as the problem space.
[0007] According to the program testing method based on the SARSA algorithm provided by the present invention, the state space in step S11 includes interface layout and control attributes, wherein the control attributes include control type, control position, and control state; the action space in step S11 includes user click, user input, and user scrolling.
[0008] According to the program testing method based on the SARSA algorithm provided by the present invention, the SARSA algorithm parameters in step S2 include learning rate, discount factor, and exploration rate.
[0009] According to the program testing method based on the SARSA algorithm provided by the present invention, step S3 further includes: S31: Based on the problem space, select the action to be executed according to the current state; S32: Execute the action to be executed, and obtain the execution status and execution reward; S33: Update the execution status and execution reward to the Q table according to the update rules; S34: Continue testing the problem space according to the updated Q table until all actions in the action space of the problem space have been executed, obtain the latest Q table, and output the latest Q table as the execution result.
[0010] According to the program testing method based on the SARSA algorithm provided by the present invention, in step S31, by... The strategy selects the action to be executed.
[0011] According to the program testing method based on the SARSA algorithm provided by the present invention, the test results in step S4 include test coverage, error detection rate, performance indicators, execution results, and test case execution records.
[0012] A second aspect of the present invention provides a program testing device based on the SARSA algorithm, comprising: Modeling module: Used to model the environment of the program under test and obtain the problem space; Initialization module: Used to initialize the SARSA algorithm parameters and obtain the test algorithm; Execution module: used to execute the problem space using the test algorithm and obtain the execution results; Calculation module: Calculates test metrics based on the execution results and obtains the test results.
[0013] A third aspect of the present invention provides a program testing device based on the SARSA algorithm, comprising: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a SARSA-based program testing device to execute a SARSA-based program testing method as described in any of the preceding claims.
[0014] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a program testing method based on the SARSA algorithm as described in any of the preceding claims.
[0015] This invention provides a program testing method, apparatus, device, and storage medium based on the SARSA algorithm. By abstracting the GUI elements of the program under test into a state space and user operations into an action space, the problem space of program testing is clearly defined, thereby simplifying the testing process. At the same time, the SARSA algorithm continuously tries different actions during the testing process to explore every corner of the state space. In addition, the reward function based on the SARSA algorithm can guide the SARSA algorithm to pay more attention to those states that may cause program abnormalities or errors, thereby enhancing the comprehensiveness of the test.
[0016] The method of this invention does not depend on a specific program structure or code implementation, but rather on testing based on program behavior and user operations. Therefore, the testing method of this invention has strong adaptability and can be used to test various types of programs, including those with complex GUIs and interactive logic.
[0017] This invention automates the testing process using the SARSA algorithm. This invention reduces manual intervention and improves the automation level of testing. It can not only reduce testing costs but also improve the accuracy and consistency of testing. At the same time, the SARSA algorithm has a fast convergence speed and can find the optimal or near-optimal testing strategy in a short time, thereby significantly improving testing efficiency.
[0018] In summary, this invention, by introducing the SARSA algorithm, solves the problems of insufficient test coverage, high test script maintenance costs, low testing efficiency, and difficulty in handling complex user interactions in traditional automated testing of Windows applications, providing an efficient and intelligent solution for automated testing of Windows applications. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0020] Figure 1 A schematic flowchart of a program testing method based on the SARSA algorithm provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a program testing device based on the SARSA algorithm provided in an embodiment of the present invention.
[0021] Reference numerals: 100, Modeling module; 200, Initialization module; 300, Execution module; 400, Calculation module. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, embodiments of this invention, and should not be construed as limiting the invention. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention. In the description of this invention, it should be understood that the terminology used is for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0023] The following is combined with Figures 1 to 2 Description of embodiments of the present invention.
[0024] like Figure 1 As shown, the first aspect of the present invention provides a program testing method based on the SARSA algorithm, comprising: S1: Perform environmental modeling on the program under test to obtain the problem space.
[0025] In step S1, the GUI elements of the Windows application are first abstracted into a state space, and user actions are abstracted into an action space, and a reward function is defined. The state space includes the application's interface layout, control states, etc.; the action space includes user actions such as clicking, inputting, and scrolling; the reward function calculates the reward value based on the test results and the expected goal.
[0026] Step S1 further includes: S11: Abstract the GUI elements of the program under test into a state space; abstract the user operations of the program under test into an action space.
[0027] The state space in step S11 includes interface layout and control attributes, and the control attributes include control type, control position, and control state; the action space in step S11 includes user click, user input, and user scrolling.
[0028] S12: Define a reward function, and output the state space, the action space, and the reward function as the problem space.
[0029] Furthermore, step S11 first defines the state space, which includes the application's interface layout, control states, etc. Specifically, the state space can be represented as: },in, Indicates the One state, The total number of states, including the control's type, position, and state (such as whether it is enabled or visible).
[0030] Next, define the action space, which includes user actions such as clicking, inputting, and scrolling. Specifically, the action space can be represented as: },in, Indicates the One action, This represents the total number of actions, including clicking buttons, entering text, scrolling pages, etc.
[0031] The reward function in step S12 is the calculation of the reward value based on the test results and the expected goal. Specifically, the reward function can be expressed as: ,in, Indicates the state Next action , Indicates the execution of an action The reward value obtained can be calculated based on indicators such as the correctness of the test results, execution time, and error detection rate.
[0032] S2: Initialize the SARSA algorithm parameters and obtain the test algorithm.
[0033] The SARSA algorithm parameters in step S2 include learning rate, discount factor, and exploration rate.
[0034] Specifically, learning rate Controlling the learning speed affects the update speed of the Q-table; the learning rate can be expressed as... general learning rate It can be set to 0.1 or 0.01; in this embodiment, it is set to 0.1; discount factor The weighting of future rewards and the update strategy of the Q table can be represented by the discount factor. Generally, discount factor It can be set to 0.9 or 0.09; in this embodiment, it is set to 0.9; exploration rate The balance between exploration and exploitation determines the update strategy of the Q-table; the exploration rate can be expressed as... general exploration rate It can be set to 0.1 or 0.05; in this embodiment, it is set to 0.1.
[0035] S3: Execute the problem space using the test algorithm to obtain the execution result.
[0036] Step S3 further includes: S31: Based on the problem space, select the action to be executed according to the current state.
[0037] In step S31, through The strategy selects the action to be executed.
[0038] Specifically, at each time step, based on the current state ,use Strategy selection action, The strategy is represented as:
[0039]
[0040] in, This indicates that the action with the largest Q value is selected. This means randomly selecting an action. Indicates the state and the execution of actions The Q-table is composed of these elements.
[0041] S32: Execute the action to be executed and obtain the execution status and execution reward.
[0042] S33: According to the update rules, update the execution status and the execution reward to the Q table.
[0043] S34: Continue testing the problem space according to the updated Q table until all actions in the action space of the problem space have been executed, obtain the latest Q table, and output the latest Q table as the execution result.
[0044] After selecting the action to be executed in step S31, the action is executed. After execution, the new status and reward are observed, and the Q table is updated according to the SARSA update rules, thus updating the status to... Continue to the next action. After subsequent tests are completed, evaluate the effect of each state-action pair based on the values in the Q table and generate a test report.
[0045] In addition, during the optimization of the search space, the learning rate needs to be adjusted based on the test results and the values in the Q-table. Discount Factor Exploration rate By iterating through multiple iterations, parameters such as [parameter name] are used to gradually improve the accuracy and efficiency of the test. Specifically, strategy optimization can be expressed as: Repeat { Execute test Evaluate test results Adjust parameters until convergence Here, convergence indicates that the policy optimization has converged.
[0046] S4: Calculate the test metrics based on the execution results to obtain the test results.
[0047] The test results in step S4 include test coverage, error detection rate, performance metrics, execution results, and test case execution records.
[0048] Furthermore, the test coverage mentioned above represents the percentage of application functionality covered by test cases. Specifically, test coverage can be expressed as: Coverage = (Number of tested functions / Total number of functions) * 100%, where Number of tested functions represents the number of tested functions, and Total number of functions represents the total number of functions. The error detection rate represents the percentage of errors detected by test cases. Specifically, the error detection rate can be expressed as: Error Detections Rate = (Number of detected errors / Total number of errors) * 100%, where Number of detected errors represents the number of detected errors, and Total number of errors represents the total number of errors. Performance metrics can represent performance indicators such as test case execution time and memory usage. Specifically, performance metrics can be expressed as: Performance = (execution time, memory usage, ...).
[0049] Then, a test report is generated based on test coverage, error detection rate, performance metrics, etc. The test report may include the following: test coverage, error detection rate, performance metrics, values in the Q table, and test case execution records.
[0050] like Figure 2 As shown, a second aspect of the present invention provides a program testing device based on the SARSA algorithm, comprising: Modeling Module 100: Used to model the environment of the program under test and obtain the problem space; Initialization module 200: Used to initialize the SARSA algorithm parameters and obtain the test algorithm; Execution module 300: used to execute the problem space through the test algorithm and obtain the execution result; Calculation module 400: Calculates test indicators based on the execution results and obtains test results.
[0051] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0052] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0053] A third aspect of the present invention provides a program testing device based on the SARSA algorithm, comprising: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a SARSA-based program testing device to execute a SARSA-based program testing method as described in any of the preceding claims.
[0054] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a program testing method based on the SARSA algorithm as described in any of the preceding claims.
[0055] Furthermore, the program testing device based on the SARSA algorithm provided by this invention can vary considerably due to different configurations or performance. It may include one or more central processing units (CPUs), for example, one or more processors and memory, and one or more storage media for storing applications or data, such as one or more mass storage devices. The memory and storage media may be temporary or persistent storage. The program stored in the storage media may include one or more modules, each module may include a series of instruction operations in the program testing device based on the SARSA algorithm. Furthermore, the processor may be configured to communicate with the storage media and execute a series of instruction operations in the storage media on the program testing device based on the SARSA algorithm.
[0056] It may also include one or more power supplies, one or more wired or wireless network interfaces, one or more input / output interfaces, and one or more operating systems, such as Windows Server, MacOSX, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that the program testing device structure based on the SARSA algorithm provided in this invention does not constitute a limitation on the device, and may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.
[0057] This invention provides a program testing method, apparatus, device, and storage medium based on the SARSA algorithm. By employing the SARSA (State-Action-Reward-State-Action) algorithm for program testing, since the algorithm tends to select actions that are more likely to discover new errors or cover more functions, this invention can intelligently select test actions and dynamically adjust the test strategy according to the test results, which not only significantly improves the efficiency of testing but also ensures the accuracy of testing.
[0058] This invention employs detailed state-space modeling of the GUI elements of the application under test, enabling more comprehensive coverage of various functions and states. The state space includes detailed information such as interface layout and control properties, allowing test cases to more accurately simulate user operations, thereby improving test coverage.
[0059] The reward function defined in this invention can calculate the reward value based on the test results and the expected goal, which helps the algorithm to identify errors more accurately. At the same time, by continuously optimizing the parameters of the SARSA algorithm (such as learning rate, discount factor, and exploration rate), this invention can gradually improve the error detection rate and ensure that test cases can discover more potential errors.
[0060] The testing method provided by this invention realizes the automation and intelligence of testing. By defining the state space, action space and reward function and initializing the SARSA algorithm parameters, the testing process can be carried out automatically without manual intervention, which not only reduces the testing cost, but also improves the reliability and consistency of the test.
[0061] This invention calculates test metrics based on execution results and generates a comprehensive test report containing information such as test coverage, error detection rate, performance metrics, values in the Q table, and test case execution records. This helps testers fully understand the test situation, evaluate the test results, and provides valuable reference for subsequent development and testing work.
[0062] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A program testing method based on SARSA algorithm, characterized in that: include: S1: Model the environment of the program to be tested and obtain the problem space; S2: Initialize SARSA algorithm parameters and obtain the test algorithm; S3: Execute the problem space through the test algorithm to obtain an execution result; S4: Calculate the test index according to the execution result to obtain the test result.
2. A program testing method based on SARSA algorithm according to claim 1, characterized in that: Step S1 further comprises: S11: abstracting the GUI elements of the program under test into a state space; abstracting the user operations of the program under test into an action space; S12: Define a reward function, and output the state space, the action space, and the reward function as a problem space.
3. A program testing method based on SARSA algorithm according to claim 2, characterized in that: The state space in step S11 includes interface layout and control attributes, and the control attributes include control type, control position, and control state; the action space in step S11 includes user click, user input, and user scroll.
4. A program testing method based on SARSA algorithm according to claim 1, characterized in that: The SARSA algorithm parameters in step S2 include learning rate, discount factor, and exploration rate.
5. A program testing method based on SARSA algorithm according to claim 1, characterized in that: Step S3 further comprises: S31: Based on the problem space, select an action to be performed according to the current state; S32: Execute the action to be executed, and obtain the execution status and execution reward; S33: updating the execution status and the execution reward to the Q table according to the update rule; S34: Continue testing the problem space according to the updated Q table until all actions in the action space of the problem space are executed, obtain the latest Q table, and output the latest Q table as the execution result.
6. A program testing method based on SARSA algorithm according to claim 5, characterized in that: In step S31, by The strategy selects the action to be performed.
7. A program testing method based on SARSA algorithm according to claim 1, characterized in that: The test results in step S4 include test coverage, error detection rate, performance indicators, execution results, and test case execution records.
8. A program testing device based on SARSA algorithm, characterized in that: include: Modeling module: used to model the environment of the program to be tested and obtain the problem space; Initialization module: used to initialize SARSA algorithm parameters and obtain the test algorithm; Execution module: used to execute the problem space through the test algorithm and obtain the execution result; Calculation module: calculates the test index according to the execution result to obtain the test result.
9. A program testing device based on SARSA algorithm, characterized in that: include: A memory and at least one processor, wherein instructions are stored in the memory; At least one of the processors calls the instructions in the memory to enable a program testing device based on the SARSA algorithm to execute a program testing method based on the SARSA algorithm as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed by the processor, a program testing method based on the SARSA algorithm as described in any one of claims 1 to 7 is implemented.