Deep reinforcement learning-based iOS application test method
By using the test agent dynamic library and fine-grained state representation of deep reinforcement learning in iOS application testing, combined with the dynamic reward function, the problems of low performance in obtaining GUI information and coarse-grained reward function design in the existing technology are solved, and a higher level of performance is achieved. code coverage and fault detection rate.
Patent Information
- Application Number
- CN202410627345.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-09-03
AI Technical Summary
In the existing iOS application testing technology, the performance of the test agent tool in obtaining GUI information is low. The testing algorithm of deep reinforcement learning is too coarse-grained in the application status representation and reward function design, making it difficult to balance exploration and utilization during the testing process, resulting in code coverage. rate and fault detection rate are not high.
An iOS application testing method based on deep reinforcement learning is designed. GUI information is obtained through the test agent dynamic library, and a reward function based on fine-grained state representation and dynamic decay strategy based on historical information is used to optimize the exploration strategy and achieve higher code coverage. rate and fault detection rate.
Through fine-grained state representation and dynamic reward functions, it is possible to more deeply explore difficult-to-reach states of iOS applications, significantly improve code coverage and fault detection rates, and optimize the balance of exploration and utilization during testing.
Smart Images

Figure CN118585431A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of software testing, and specifically is an iOS application testing method based on deep reinforcement learning. Background Art
[0002] App Store is the only official app store for the iOS platform. By the end of 2022, the number of apps on the App Store has reached 1.78 million. Ensuring the security quality of these apps is very important for improving user experience. Effective iOS app testing technology is the key to achieving this goal.
[0003] GUI (Graphical User Interface) automated testing is one of the most important parts of mobile application testing. It mainly involves simulating clicks, slides, inputs and other operations to check whether the application functions work as expected. The first problem in GUI automated testing of iOS applications is to obtain the GUI status of the current iOS application (page control information) and inject UI events (such as clicks, slides, etc.). Appium is currently the most widely used iOS application testing tool. However, Appium has poor performance, takes several seconds to obtain information, and cannot expand information, so it cannot meet the needs of automated testing well.
[0004] Random-based testing methods inject arbitrary UI events into applications for testing. However, random testing generates a large number of invalid and redundant events, which greatly reduces the effectiveness of testing. In order to reveal application behaviors that are difficult to achieve with random-based methods, many systems use symbolic execution to find all feasible program paths for test generation. However, it remains challenging to scale them up in practice due to the high computational cost.
[0005] Model-based testing is a popular testing solution that generates test inputs based on a model to systematically explore an application. The model is a finite state machine that reflects the behavior space of the application under test. Each state usually represents an application page, and each transition between states is marked as an input event. However, due to its closed nature, it is not easy to obtain the information needed for modeling in the iOS system.
[0006] Testing methods based on reinforcement learning have been widely used in Android application testing problems, but there are few attempts in iOS application testing. Tabular reinforcement learning uses a fixed table to store state-action associated values, but this form is basically unusable for high-dimensional situations. Deep reinforcement learning replaces the tabular method with deep neural networks. Deep neural networks can handle high-dimensional situations, and the learned value function is learned by one or more neural networks from the states that have already occurred. For scenarios such as mobile applications with huge state spaces, using deep reinforcement learning can achieve better results than tabular reinforcement learning. However, the existing testing algorithms based on deep reinforcement learning are too coarse-grained in the application state representation and reward function design, and cannot balance exploration and utilization during the testing process. Summary of the invention
[0007] In view of the problems existing in the above-mentioned iOS application testing technology, such as the poor performance of the existing test agent tools in acquiring GUI information, and the overly coarse-grained design of the application state representation and reward function of the deep reinforcement learning test algorithm, the present invention discloses an iOS application testing method based on deep reinforcement learning. The deep reinforcement learning test algorithm is constructed by utilizing the GUI information acquired by the test agent dynamic library. The exploration strategy is learned in a more fine-grained manner during the testing process, and it can reach the states that are difficult for some iOS applications to reach more deeply, thereby achieving higher code coverage and fault detection rate.
[0008] The present invention provides an iOS application testing method based on deep reinforcement learning, comprising the following steps:
[0009] Step 1: Build a test agent dynamic library for obtaining GUI information and integrate it into the executable file of the tested iOS application. The test agent dynamic library is a binary file with the suffix .framework, which has the functions of obtaining the GUI information of the iOS application, injecting GUI events, and generating test reports.
[0010] The test agent dynamic library includes six modules: the Hook module realizes starting the communication monitoring module when the tested iOS application is started; the communication monitoring module monitors the communication of the specified device port until the tested iOS application is closed, sends the instruction sent by the host to the instruction parsing module, and returns the execution result to the host after the execution of the instruction action is completed; the instruction parsing module parses the instruction, and calls the GUI information acquisition module, the GUI event injection module and the code coverage module according to the parsing result; the GUI information acquisition module acquires the GUI information of the tested iOS application in real time, and the instructions in the module include acquiring GUI information UIInfo, acquiring all page information allVCs, and acquiring current page information currentVC. The module filters the acquired information and acquires the necessary information of all controls under the current page; the GUI event injection module is used to simulate the actions of the executor of the tested iOS application; the code coverage module controls the start and storage of the code coverage statistics of the tested iOS application, and the instructions in the module include starting code coverage statistics and saving code coverage.
[0011] Step 2: Set the test script and test parameter script on the host, install and start the tested application with integrated test agent dynamic library on the specified iOS device, wake up the communication monitoring module, and monitor the communication of the specified port of the iOS device.
[0012] Step 3: The host sends the allVCs instruction to the test agent library to obtain all page information of the current application under test and count the number of pages of the application under test for the historical information vector encoding in the state representation of the subsequent test algorithm.
[0013] Step 4: The host sends the commands UIInfo and currentVC to the test proxy library to obtain the GUI information of the current application and the current page information respectively. These two types of information are combined with all the page information obtained in step 3 and mapped into a fine-grained application state representation based on historical information.
[0014] The current fine-grained state of the tested iOS application is represented by 01 coding, which consists of three parts: historical information vector, current page unique hot coding, and current page control vector. The historical information vector records all the pages that have been explored since the start of the test, the current page unique hot coding represents the page of the tested iOS application at the current moment, and the current page control vector represents the control state contained in the current page.
[0015] Step 5: The host loads the deep reinforcement learning algorithm test model and inputs the current fine-grained state of the iOS application under test into the test model. The test model outputs the next action of the iOS application under test, that is, which control and action of the current page of the application needs to be operated next.
[0016] Step 6: The host sends the next action instruction to the test agent library of the iOS application under test, and the GUI event injection module in the test agent library executes the corresponding action in the instruction on the corresponding control of the current page of the iOS application under test, either by clicking or sliding.
[0017] Step 7. After executing the specified action, the test agent dynamic library starts to collect the current environmental status of the application under test. Check whether this action has generated new faults. If there are new faults, transfer the fault log from the iOS device to the host and restart the application under test on the iOS device. If no fault occurs, update the current code coverage, then update the GUI information of the application under test at this moment and generate a new fine-grained state representation of the iOS application under test based on the current page of historical information. Finally, calculate the reward value of this operation. The reward value of the action is calculated by a reward function based on a dynamic attenuation strategy. This reward function encourages the test model to explore new faults or new states of the application under test, and gives a penalty if it does not cause any state changes.
[0018] The reward function is expressed as follows:
[0019]
[0020] Among them, dou(s t ) indicates that the application under test is in state s t The unexplored degree under , is calculated as: d(s t ) is in state s t The number of actions that have been executed, e(s t ) is in state s t The number of all actions that can be performed under the given condition; when there is a new fault, a maximum reward μ1 is given; when there is a new state, a medium reward μ2 is given. In order not to fall into the local optimum, the unexplored degree is used to control the reward amplitude of the new state; if the current operation does not generate a new fault or a new state, a penalty of -μ3 is given.
[0021] Step 8. The deep reinforcement learning test algorithm model receives the reward for this behavior and iterates and optimizes the test strategy.
[0022] Step 9. Use the optimized test model to continue to step 4, and then execute steps 4 to 8 to obtain new GUI information for the application, calculate the new next action, calculate the reward value of the new action, and update the test model. Repeat this process until the test time or test step limit set before the test starts is reached.
[0023] Compared with the prior art, the advantages of the present invention are:
[0024] (1) The test agent dynamic library designed by the method of the present invention can obtain the GUI information of iOS applications, inject UI events, and generate test reports with high performance and accuracy. The test agent library screens the obtained GUI information and filters out invalid control information that will affect the modeling of the test algorithm, such as empty views that are only used for layout. At the same time, the GUI information supports expansion, and new information can be added according to modeling requirements.
[0025] (2) The method of the present invention designs a fine-grained representation of application status based on historical information. In the test exploration process, it is generally hoped not to repeatedly explore pages that have already been explored. However, in the existing application status representation, there is no relevant information about the explored pages, and the test algorithm cannot know that the current application has already explored a state. By adding historical information to the application status representation, the method of the present invention can enable the test algorithm to have more judgment information in generating strategies.
[0026] (3) The method of the present invention designs a reward function based on a dynamic decay strategy. During the test process, the model is usually encouraged to explore new states of the application, and a reward is given for discovering new states. However, in the existing reward function, the reward design is too coarse-grained, and a large reward is given for a new reward caused by a page that has been explored more thoroughly. The method of the present invention controls the reward when discovering a new state by introducing the page's unexplored degree. For a page that has been explored thoroughly, only a small reward can be obtained, which better balances exploration and utilization during the test process.
[0027] (4) Experiments have shown that the testing method of the present invention can reach some application states that were previously difficult to achieve, balancing exploration and utilization during the testing process and further improving code coverage and fault detection rates. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is the overall implementation architecture diagram of the iOS application testing method of the present invention;
[0029] Figure 2 It is the overall architecture diagram of the test agent dynamic library of the present invention;
[0030] Figure 3 It is a test proxy dynamic library performance test result diagram implemented by the present invention;
[0031] Figure 4 It is a test result diagram of the code coverage rate of the test tool implemented by the present invention;
[0032] Figure 5 It is a test result diagram of the fault detection rate of the test tool implemented by the present invention;
[0033] Figure 6This is a graph of ablation experiment results optimized by the test tool implemented by the present invention. DETAILED DESCRIPTION
[0034] The present invention will be further described in detail below with reference to the accompanying drawings and implementation examples.
[0035] The present invention is an iOS application testing method based on deep reinforcement learning. It uses a test agent dynamic library to obtain GUI information with high performance, and proposes a deep reinforcement learning testing method based on historical information-based application fine-grained state representation and a reward function based on a dynamic decay strategy. During the test process, a deep reinforcement learning test algorithm is used to adaptively learn the exploration strategy. In repeated test iterations, some iOS application states that were previously difficult to reach can be reached, thereby achieving high code coverage and fault detection rate.
[0036] like Figure 1 As shown, the overall implementation architecture of the test method / tool of the present invention first injects the test agent dynamic library used to obtain GUI information, inject GUI events, and generate test reports into the executable file of the application under test. Then the iOS application is installed in the iOS device for testing, and the application under test is started. The host obtains the current GUI information of the application and encodes it into the fine-grained state representation based on historical information application designed by the present invention by communicating with the test agent dynamic library. Then the state representation is passed into the deep reinforcement learning model, the next action is calculated, and the test action is executed through the test agent dynamic library, and the reward function based on the dynamic decay strategy designed by the present invention is used to calculate the corresponding reward value. The deep reinforcement learning model adaptively learns the exploration strategy by receiving the reward value, and repeats the test process until the test time set initially is reached. Finally, the corresponding test report is generated according to the test results. The test agent dynamic library designed by the present invention, the fine-grained state representation based on historical information application, and the reward function based on the dynamic decay strategy balance the exploration and utilization in the test process, and further improve the high code coverage and fault detection rate.
[0037] The core contents of the present invention are as follows: (1) A test agent dynamic library is designed for iOS application testing, which can obtain iOS application GUI information, inject GUI events, generate test reports and other functions with high performance and accuracy. (2) A fine-grained state representation method for iOS applications based on historical information is designed for deep chemical testing algorithms to provide more information for the test algorithm to generate decisions and avoid repeatedly entering pages that have been explored. (3) A reward function based on a dynamic attenuation strategy is designed, which can dynamically give reward values according to the degree of exploration of the current page. The more thorough the exploration, the less reward; the less exploration, the more reward.
[0038] The following describes the implementation of the specific steps of the iOS application testing method based on deep reinforcement learning in an embodiment of the present invention.
[0039] Step 1: Integrate the test agent dynamic library designed by the present invention into the tested iOS application. The host obtains various information and performs related operations by interacting with the test agent dynamic library.
[0040] The constructed test agent dynamic library is a binary file with the suffix .framework, which has functions such as obtaining current application GUI information, injecting GUI events, and generating test reports.
[0041] If you have the source code of the iOS application under test, you can import the test agent dynamic library file directly into the source code project. If you download the application from the App Store, you need to unpack the executable file, then inject the test agent dynamic library into the executable file through the iOS dynamic library injection technology, and then re-sign it.
[0042] like Figure 2 As shown, the test agent dynamic library is designed into six modules, including a Hook module, a communication monitoring module, an instruction parsing module, a GUI information acquisition module, a GUI event injection module, and a code coverage module.
[0043] The Hook module can change the execution order of the startup methods in the tested iOS application. By modifying the makeKeyAndVisible method of the UIWindow class in the tested iOS application code, the communication monitoring module is started at the same time when the iOS application is started, and the communication monitoring of the specified device port is performed. The makeKeyAndVisible method is used to display the current window and place the window in front of all other windows at the same level or lower.
[0044] The communication monitoring module is a service that will always exist in the process until the application under test is closed. When the communication monitoring module receives the command sent by the host, it will hand the command to the command parsing module for parsing. When the command action is executed, the communication monitoring module will return the execution result to the host.
[0045] The instruction parsing module will execute the corresponding module methods (i.e., the corresponding instructions in the modules) in the three modules, namely, the GUI information acquisition module, the GUI event injection module, and the code coverage module, according to different parsing results.
[0046] The GUI information acquisition module can obtain the GUI information related to the application under test in real time. The commands include UIInfo (GUI information), allVCs (all page information), and currentVC (current page information). In order to avoid some invalid information, such as empty views and hidden views used for layout, which may interfere with the subsequent test algorithm modeling, relevant filtering conditions are set for the obtained GUI information. The filtered GUI information contains the necessary information of all controls on the current page, including the control coordinate frame, control type name className, control events actions, control gesture events gestures, control identifier identifier, and control text text.
[0047] The GUI event injection module can simulate people to perform click, slide and other actions on iOS applications. The instructions include click touch, slide pan, etc.
[0048] The code coverage module can control the start and save of iOS application code coverage statistics. The instructions include startCoverage to start code coverage statistics and saveCoverage to save code coverage.
[0049] Step 2: Set the test script and test parameter script on the host, detect and start the specified iOS device, and then install and start the iOS application under test.
[0050] When the iOS application is started, the Hook module in the test agent dynamic library will modify the execution order of the startup method, wake up the communication monitoring module in the test agent dynamic library, and monitor the communication of the specified port of the iOS device. The host communicates with the iOS device through the port monitored by the test agent, and indirectly operates the application under test.
[0051] The set test script and sequencing parameter script are stored on the host. In the host's sequencing parameter script file, you can enter various test-related parameters to control the entire test process. Specific parameters include:
[0052] observation_space_length: This parameter is used to control the total length of the iOS application state representation. The default value is 2000.
[0053] Iterations: This parameter is used to control how many rounds the entire test is executed. The default is 3 rounds, which means that an iOS application will be tested three times.
[0054] max_timesteps: This parameter is used to control the maximum number of steps executed in each round of testing. When this number of steps is exceeded, this round of testing ends. The default value is 2000 steps.
[0055] timer: This parameter controls the maximum time of each round of testing. When the test duration exceeds this time, this round of testing ends. The default value is 30 minutes.
[0056] coverage: This parameter controls whether code coverage is collected during the test.
[0057] Step 3: The host sends the allVCs command to the test agent library to obtain all page information of the current application.
[0058] The fine-grained application state representation based on historical information designed by the present invention needs to know how many pages the current application has in total, so as to record which pages have been visited. Before the application test begins, the page information of the entire application is obtained through the test agent dynamic library, which is used for the historical information vector encoding in the state representation of the subsequent test algorithm. Let the number of all pages of the current application be m.
[0059] Step 4: The host sends the command UIInfo and currentVC to the test proxy library to obtain the GUI information of the current application under test and the current page information respectively. These two types of information are combined with all the page information obtained in step 3 and mapped into a fine-grained application state representation based on historical information.
[0060] The goal of iOS application GUI automated testing is to explore as many new states of the tested iOS application as possible, improve code coverage and fault detection rate. Therefore, during the test process, the model should be provided with enough information so that the model can explore more intelligently. If too little information is provided, the model is likely to fall into some repetitive actions and fail to find new states.
[0061] The goal of automated testing is to explore new states of iOS applications as much as possible, so as to achieve higher code coverage and fault detection rate. Based on this, it is generally expected that the test model will not re-enter the pages that have been explored as much as possible, but explore new pages. However, according to the current coding method, the model is not clear about which states it has explored in the past. The present invention provides relevant information by adding a historical information vector.
[0062] The current fine-grained state of the iOS application is represented by 01 encoding, which consists of three parts: the historical information vector, the one-hot encoding of the current page, and the current page control vector. The historical information vector records the status of all pages that have been explored from the beginning to the present, the one-hot encoding of the current page represents the page where the application is at the moment, and the current page control vector represents the status of the controls contained in the current page.
[0063] The specific formula for expressing the fine-grained application state based on historical information designed by the present invention is:
[0064] GUI state=(h1,...h m ,v1,...v m ,w1,...w n )
[0065] Among them, the first part of the state vector h1,...h m Indicates the historical state that the application has explored in the past. If the i-th page of the application has been explored, then h i The value is 1, otherwise the value is 0. The second part v1,...v m is a one-hot encoding, indicating the page where the current iOS application is located. If the current page is the jth page, then v j The value of w1,...w n The state vector represents the distribution of control elements on the current page. If the kth control is available on the current page, then w k The value of is 1, otherwise it is 0. n represents the preset number of controls, which can be preset to a relatively large value. When the page is continuously accessed, the control number will be obtained.
[0066] For example, suppose the current iOS application contains three pages: HomeVC, LoginVC, and UserVC. It contains four controls: widget[UITextField,(30,100,120,60),'UserName'], widget[UITextField,(30,200,120,60),'Password'], widget[UIButton,(30,300,60,60),'Login'], widget[UITableView,(0,0,375,667),'content']. The above three parts of the code can be expressed as:
[0067] Explore the historical state vector:
[0068] (h1, h2, h3) = (Home history, Login history, User history)
[0069] The page the application is currently on is uniquely encoded:
[0070] (v1,v2,v3)=(HomeVC,LoginVC,UserVC)
[0071] Page Control Vector:
[0072] (w1,w2,w3,w4)=(widget[UITextField,(30,100,120,60),'UserName'],widget[UITextField,(30,200,120,60) ,'Password'], widget[UIButton,(30,300,60,60),'Login'], widget[UITableView,(0,0,375,667),'content'])
[0073] Assume that you have explored the HomeVC and LoginVC pages in the past. And you are currently on the HomeVC page. The controls on the current page are: widget[UITextField,(30,100,120,60),'UserName'], widget[UITextField,(30,200,120,60),'Password'], widget[UIButton,(30,300,60,60),'Login']. Then you can get a complete fine-grained status code of the tested iOS application:
[0074] GUI state = (h1,h2,h 3, v1,v2,v 3, w1,w2,w3,w4)=(1,1,0,1,0,0,1,1,1,0)
[0075] In the above examples, each part of the code is represented by 0 or 1. In the exploration history vector code, 0 means that the page has not been explored, and 1 means that the page has been explored. The one-hot encoding of the current page of the application, 1 means the current page, and 0 means it is not currently on this page. In the page control vector, 0 means that the current page does not have this control, and 1 means that this control is on the current page.
[0076] Step 5: The host loads the deep reinforcement learning algorithm test model and passes the current application fine-grained state representation information based on historical information generated in step 4 to the model. The deep reinforcement learning model outputs the next action of the iOS application based on the state, that is, which control and action of the current page of the application needs to be operated next.
[0077] The present invention adopts the deep reinforcement learning SAC (Soft Actor-Critic) algorithm as the test algorithm by default. The SAC algorithm uses the maximum entropy model and solves the reinforcement learning problem of discrete action space and continuous action space. It is off-policy reinforcement learning and belongs to the category of maximum entropy reinforcement learning. This algorithm adds an entropy term to the optimization objective to increase the randomness of the strategy. The added entropy term has a target value. When the entropy of the strategy is lower than the target value, the proportion of the entropy term in the strategy loss function will increase, and vice versa.
[0078] In the method of the present invention, GUI information and related page information provided by the proxy dynamic library are received, and then the information is encoded to obtain the current fine-grained state representation of the tested iOS application, and the test model implemented by the deep reinforcement learning algorithm SAC is input to calculate the next action that the iOS application needs to perform.
[0079] Step 6: The host sends the next action instruction to the test agent library of the iOS application under test, and the test agent library will perform the corresponding action on the control, either by clicking or sliding.
[0080] For the obtained GUI information, it is necessary to make a judgment on its GUI events and gesture events to decide what operation to take. The GUI information provided by the test agent library already contains complete executable actions and gesture events. In iOS applications, gesture events have the same functions as GUI events, and also provide more event effects such as dragging. When the GUI event injection module injects event operations into the iOS application under test, it also judges the action events and gesture events on the corresponding controls. For the types of controls that can slide, in order to ensure the integrity of the test, a random parameter is added to control the direction of sliding. The sliding directions are divided into up, down, left, and right, which can cover most actions in multiple tests.
[0081] Step 7: After executing the specified action, start collecting the current environment status of the application under test.
[0082] If there is a new fault log, the log is transferred from the iOS device to the host, and the tested application on the iOS device is restarted. The fault log records the path set where the fault occurred, and the operation before the fault can be traced back through the record. If no fault occurs, the current code coverage information is updated first, then the GUI information at this moment is updated and a new fine-grained state representation of the application on the current page based on the historical information is generated, and finally the reward value of this state change is calculated.
[0083] In reinforcement learning, the reward function plays a crucial role. It defines the immediate feedback that the agent gets after taking a specific action in a specific state. The reward function is a core component of the reinforcement learning algorithm, which directly affects the learning process of the agent and the final learned strategy. The agent needs to strike a balance between exploring unknown states and using existing knowledge. The design of the reward function can encourage or inhibit the agent's exploration behavior.
[0084] In the automated testing of iOS applications, the expected maximum reward is to maximize the fault detection rate and code coverage in the entire automated testing process. Therefore, behaviors that improve code coverage and fault detection rates need to be rewarded, while behaviors that hinder the improvement of code coverage and fault detection rates need to be given negative feedback.
[0085] The reward value is calculated using the reward function based on the dynamic decay strategy newly designed by the present invention. The reward function encourages the reinforcement learning model to explore new faults or new states of the application under test, and gives a penalty for not causing any state changes. First, when a new fault is discovered, the reward function will give a maximum reward. Then, if the state of the application under test changes, such as entering a new page and causing the control of the current page to change (position, text), a reward will be given. The present invention designs a dynamic decay strategy for state changes to control the reward value in a finer granularity, encouraging the test algorithm to explore more unexplored states, that is, the degree of exploration of the current page is measured. The higher the degree of exploration, the less reward is obtained when changes are caused; the lower the degree of exploration, the more reward is obtained when changes are caused. Finally, if the current operation does not produce any changes, a certain penalty is given.
[0086] The method of the present invention first proposes an evaluation criterion called "degree of unexplored" (dou for short) to measure the degree of exploration of each application state, and its formula is:
[0087]
[0088] Among them, d(s t ) is state s t The number of actions that have been executed, e(s t ) is state s t The number of all actions that can be performed. Intuitively, the more unexplored components the current page contains, the higher the unexplored degree, and vice versa.
[0089] Combined with the above “unexplored degree” formula, the reward function r based on the dynamic decay strategy designed by the present invention is t The following formula:
[0090]
[0091] Here, the reward is divided into three cases. First, if the program crashes at time t during the test, and the crash has not occurred in previous tests, in order to encourage this behavior, the maximum reward for this case is μ1=500. Second, if the state s in the test t+1 Is a new state that has never appeared in the previous moment, then this situation will also give a good reward μ2=300. In order not to fall into the local optimum, the reward for the new state is discounted. The present invention uses "unexplored degree" to control the magnitude of the reward. If the page has been fully explored, then even if a new state is triggered, no reward will be obtained. The purpose is to encourage the model to explore new pages as much as possible. Third, if the explored state is a state that has been explored in the past, a penalty will be given, that is, the reward value is -μ3=-100. The reward function plays a vital role in guiding the test tool to explore new states and faults, and better results can be achieved through deep neural networks.
[0092] Step 8. The test model of the deep reinforcement learning algorithm receives the reward for this behavior and iterates and optimizes the test strategy.
[0093] Step 9: Repeat steps 4 to 8 using the new deep reinforcement learning test algorithm model until the test time or test step limit set before the test begins is reached. That is, obtain new GUI information for the application, calculate the new next action, calculate the reward value for the new action, and update the test algorithm model. Repeat this process over and over again. After a long period of iteration, the deep reinforcement learning model exploration strategy gradually tends to balance, improving the code coverage and fault detection rate of the application under test.
[0094] The test tool designed using the method of the present invention is named Dolphin. Three experiments are conducted here: (1) Performance testing using the test agent dynamic library designed by the present invention. (2) Code coverage and fault detection rate testing using the deep reinforcement learning-based iOS application testing method designed by the present invention. (3) Ablation experiment for the optimization design of the present invention.
[0095] The test applications for this experiment are 20 popular open source programs collected on GitHub.
[0096] like Figure 3As shown, the performance test results of the test agent dynamic library designed by the present invention are shown. Six applications were selected from 20 open source programs, and four pages were randomly selected for testing. The test content is the time consumed to read the current page GUI information and the number of GUI controls obtained. Two test tools are used for comparison, one is Apple's native test framework XCUITest, and the other is the most commonly used open source test tool Appium. From the results, Dolphin has the strongest performance, because Dolphin injects Hook through the dynamic library, directly obtains the current page control information of the application, and only dumps the necessary information, optimizes the control information acquisition process, and reduces the amount of data transmission.
[0097] like Figure 4 , Figure 5 As shown, the test results of code coverage and fault detection rate are respectively performed using the iOS application testing method based on deep reinforcement learning designed by the present invention. The test uses three existing algorithms for comparison, namely Monkey (random testing strategy), Stoat (model-based testing strategy), and ARES (testing strategy based on deep reinforcement learning). A total of 20 applications were tested, and each application was tested for 3 rounds, each round for 1 hour. Through the analysis of the results, the iOS application testing method based on deep reinforcement learning proposed by the present invention achieved the best effect, and the average code coverage and fault detection rate were higher than those of the existing algorithms.
[0098] like Figure 6 As shown in the figure, it is the ablation experiment result for the optimization design of the present invention. Three variant algorithms are used for comparison: (1) Dolphin-history sets the reward function in reinforcement learning to a constant, but retains the historical information state in the state information; (2) Dolphin-reward does not add historical state information to the state representation of reinforcement learning, but retains the dynamic reward function design; (3) Dolphin-none does not add historical state information to the state representation of reinforcement learning, nor does it add a dynamic reward function design. As in the above experiment, a total of 20 applications were tested, each application was tested for 3 rounds, each round lasting 1 hour, and the code coverage was recorded every 3 minutes. The results show that the variant algorithm Dolphin-none, which neither adds exploration history information to the reinforcement learning state representation nor adds a dynamic reward function design, has the weakest performance. Secondly, Dolphin-history, which adds exploration history information, performs better than Dolphin-reward, which uses a dynamic decay reward function design. The Dolphin algorithm that uses both exploration history information and a dynamic decay reward function design achieved the best results.
[0099] Except for the technical features described in the specification, all of them are known technologies to those skilled in the art. The present invention omits the description of known components and known technologies to avoid redundancy and unnecessary limitation of the present invention. The implementation methods described in the above embodiments do not represent all implementation methods consistent with the present application. On the basis of the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative labor are still within the protection scope of the present invention.
Claims
1. A method for testing iOS applications based on deep reinforcement learning, characterized in that: The steps include: Step 1: Build a test agent dynamic library and integrate it into the executable file of the tested iOS application; the test agent dynamic library is used to obtain the GUI information of the iOS application, inject GUI events, and generate a test report; The test agent dynamic library is implemented as a binary file with the suffix .framework, which contains the following six modules: The Hook module starts the communication monitoring module when the iOS application under test is started; The communication monitoring module monitors the communication of the specified device port until the iOS application under test is closed, sends the command sent by the host to the command parsing module, and returns the execution result to the host after the execution of the command action is completed; The instruction parsing module parses the instruction, and calls the GUI information acquisition module, the GUI event injection module and the code coverage module according to the parsing result; The GUI information acquisition module acquires the GUI information of the tested iOS application in real time. The instructions in this module include acquiring GUI information UIInfo, acquiring all page information allVCs, and acquiring current page information currentVC. This module filters the acquired information and acquires the necessary information of all controls on the current page. The GUI event injection module is used to simulate the actions of the executor on the tested iOS application; The code coverage module controls the start and save of the code coverage statistics of the tested iOS application. The instructions in this module include starting code coverage statistics and saving code coverage. Step 2: Set the test script and test parameter script on the host, install and start the tested iOS application with the integrated test agent dynamic library on the specified iOS device, wake up the communication monitoring module, and monitor the communication of the specified device port; Step 3: The host sends the allVCs command to the test proxy library to obtain all page information of the tested iOS application and count the number of pages; Step 4: The host sends the commands UIInfo and currentVC to the test proxy library to obtain the GUI information and current page information of the tested iOS application respectively, and determine the current fine-grained state of the tested iOS application; The fine-grained state of the tested iOS application consists of three parts: a historical information vector, a one-hot code of the current page, and a current page control vector; the historical information vector records all the pages that have been explored since the start of the test, the one-hot code of the current page indicates the current page of the tested iOS application, and the current page control vector indicates the control state contained in the current page; Step 5: The host loads the test model of the deep reinforcement learning algorithm, inputs the current fine-grained state of the tested iOS application into the test model, and the test model outputs the next action of the tested iOS application; Step 6: The host sends the next action instruction to the test agent library of the tested iOS application, and the GUI event injection module performs an action on the corresponding control of the current page of the tested iOS application according to the instruction; Step 7: After executing the action on the tested iOS application, the test agent dynamic library starts to collect the current environment status of the tested application, checks whether this action has generated new faults, if so, transmits the fault log to the host, restarts the tested iOS application, if not, updates the current code coverage; calculates the reward value of this action; Step 8: The test model receives the reward for this action and iterates and optimizes the test strategy; Step 9. Use the optimized test model to continue to step 4 until the test time limit or test step setting set in the test parameter script is reached.
2. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In the step 1, the GUI information acquisition module filters the acquired information to obtain necessary information of all controls in the current page, including control coordinate frame, control type name className, control event actions, control gesture event gestures, control identifier identifier, and control text text.
3. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In step 2, the test parameter script set on the host contains the following parameters: The parameter observation_space_length is used to control the total length of the measured application state representation; The parameter iterations is used to control the total number of rounds to be executed for the entire test; The parameter max_timesteps is used to control the maximum number of steps executed in each round of testing; The parameter timer is used to control the maximum time of each round of testing; The coverage parameter is used to control whether code coverage is collected during the test process.
4. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In step 4, the current fine-grained state of the tested iOS application is represented as a GUI state, as follows: GUI state=(h1,...h m ,v1,...v m ,w1,...w n ) Among them, the first part h1,...h m Indicates the historical state that the application has explored in the past. If the i-th page of the application has been explored, then h i The value of is 1, otherwise the value is 0; the second part v1,...v m is a one-hot encoding, indicating the page where the tested application is currently located. If the current page is the jth page, then v j The value of v is 1, and the other v i (i=1,2…m and i≠j) values are all 0; the third part w1,...w n Indicates the control status of the current page. If the kth control is available, then w k The value of w is 1, otherwise k The value is 0; m represents the number of all pages of the tested iOS application; n is the number of preset controls.
5. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In step six, when the GUI event injection module injects event operations into the tested iOS application, it simultaneously determines the action events and gesture events on the corresponding controls, and for sliding actions, controls the sliding direction by setting random parameters.
6. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In step 7, the reward value of the action is calculated by a reward function based on a dynamic decay strategy, which encourages the test model to explore new faults or new states of the application under test and imposes a penalty on actions that do not cause any state change; The reward function is expressed as follows: Among them, dou(s t ) indicates that the application under test is in state s t The unexplored degree under , is calculated as: d(s t ) is in state s t The number of actions that have been executed, e(s t ) is in state s t The number of all actions that can be performed under the given condition; when there is a new fault, a maximum reward μ1 is given; when there is a new state, a medium reward μ2 is given. In order not to fall into the local optimum, the unexplored degree is used to control the reward amplitude of the new state; if the current operation does not generate a new fault or a new state, a penalty of -μ3 is given.
7. The iOS application testing method based on deep reinforcement learning as claimed in claim 1, characterized in that: In step seven, the fault log records the set of paths where the fault occurs, and the operation before the fault can be traced back through the record.
Citation Information
Cited By
Application test method and device, electronic equipment, product and storage medium
CN119938531A
Computer-implemented method for exploratory testing of a technical system under test
EP4826546A1
Computer-implemented method for carrying out explorative testing of a technical system to be tested
WO2026219737A1
