CN-114911708-B - UI application testing method and device
Abstract
The invention discloses a method and a device for testing UI (user interface) applications. Firstly, extracting an interactable event of a page, judging whether the interactable event is executed, searching for an interactable event through a Monte Carlo tree if all the interactable events of the page are executed, and executing the interactable event. According to the invention, through Monte Carlo tree search decision, the proportion of test case numbers allocated to the test points is balanced, so that the overall test efficiency is improved.
Inventors
- ZHANG TIAN
- PAN MINXUE
- XU HAO
Assignees
- 南京大学
Dates
- Publication Date
- 20260512
- Application Date
- 20220527
Claims (6)
- 1. A method of UI application testing, comprising the steps of: step S1, loading and executing UI application to be tested, and selecting a currently-stayed interface as a current page; Step S2, judging whether the current page is an interface of the UI application to be tested, if the current page is not the interface of the UI application to be tested, re-executing the step S1, otherwise, extracting page control layout information of the current page, extracting interactable events of all controls of the page through analysis of the page control layout information to form an interactable event set of the current page, and extracting a subsequent page jump set of the current page through page matching; step S3, judging whether an unexecutable interactable event exists in the interactable event set of the current page through the subsequent page jump set of the current page, if so, randomly selecting an unexecutable interactable event, otherwise, searching for an interactable event through a Monte Carlo tree; Step S4, executing the selected interactable event, adding the page subjected to the jumping of the interactable event and the selected interactable event into a subsequent page jumping set of the current page, and simultaneously selecting the page subjected to the jumping as the current page to repeat the steps S2, S3 and S4 until the ending condition is met; the searching for an interactable event through the Monte Carlo tree comprises the following steps: S31, constructing a root node of a Monte Carlo tree by using a current page; step S32, performing traversal search on the Monte Carlo tree by taking the root node of the Monte Carlo tree as an initial current node to obtain a search node; step S33, calculating a return value of the search node by random walk of a subsequent page of the page corresponding to the search node; Step S34, updating the return value and the simulation times of the searching node and the ancestor nodes thereof to increase the return value of the searching node by one; step S35, repeating steps S32 to S34 until the iteration number reaches a preset threshold; Step S36, calculating UCT values of all the child nodes of the Monte Carlo root node, and selecting interactable events corresponding to the child node with the largest UCT value as a current interface; In the step S32, if the subsequent page jump set of the page corresponding to the current node is not empty and the pages in the subsequent page jump set are all children of the current node, the UCT value of each children node is calculated, the children node with the largest UCT value is selected as the current node to continue traversing the Monte Carlo tree until the subsequent page jump set of the current node is empty or the pages which are not children of the current node exist in the subsequent page jump set; in the step S33, a page corresponding to the search node is taken as a current page, and a subsequent page is randomly selected from a subsequent page jump set of the current page as the current page until the subsequent page jump set of the current page is empty, wherein MINREWARD is taken as a return value of the search node if the current page is not an interface of the UI application to be tested, or maxReward is taken as a return value of the search node, wherein MINREWARD is less than maxReward; The UCT value of the child node is calculated by adopting the following formula: UCT (V (i))=Q (V (i))/N (V (i))+c×sqrt (log (N (V))/N (V (i))), wherein, V (i) represents the ith child node of node V; UCT (V (i)) represents the UCT value of the ith child node of node V; Q (V (i)) represents the benefit value of the ith child node of node V; n (V (i)) represents the number of simulations of the ith child node of node V; N (V) is expressed as the number of simulations of node V; log is a logarithmic function; sqrt is a square root function; c is a preselected set coefficient.
- 2. The method of UI application testing of claim 1, wherein the end condition is a test coverage greater than a first limit and a test time greater than a second limit, wherein test coverage = number of interactable events performed/total number of interactable events.
- 3. The method of UI application testing of claim 1, In the step S1, when the interactable event of each control of the page is extracted through analysis of the layout information of the page control, the corresponding page information is found in the page information set through matching of the layout information of the page control, if the corresponding page information is not found in the page information set, the interactable event of each control of the page is extracted through analysis of the layout information of the page control, the page information is added into the page information set, and otherwise, the corresponding interactable event and the subsequent page skip set are extracted from the corresponding page information.
- 4. An apparatus for UI application testing, comprising the following modules: the module M1 is used for loading and executing the UI application to be tested and selecting the interface which is currently stayed as the current page; The module M2 is used for judging whether the current page is an interface of the UI application to be tested, and re-executing the module M1 if the current page is not the interface of the UI application to be tested, otherwise extracting page control layout information of the current page, extracting interactable events of all controls of the page through analysis of the page control layout information to form an interactable event set of the current page, and extracting a subsequent page jump set of the current page through page matching; The module M3 is used for judging whether an unexecutable interactable event exists in the interactable event set of the current page through the subsequent page jump set of the current page, randomly selecting one unexecutable interactable event if the unexecutable interactable event exists, otherwise searching for one interactable event through a Monte Carlo tree; The module M4 is used for executing the selected interactable event, adding the page subjected to the jumping of the interactable event and the selected interactable event into a subsequent page jumping set of the current page, and simultaneously selecting the page subjected to the jumping as the current page repeating modules M2, M3 and M4 until the ending condition is met; the searching for an interactable event through the Monte Carlo tree comprises the following modules: A module M31 for constructing a root node of the Monte Carlo tree with the current page; The module M32 is used for performing traversal search on the Monte Carlo tree by taking the root node of the Monte Carlo tree as an initial current node to obtain a search node; the module M33 is used for calculating the return value of the search node through the random walk of the subsequent page of the page corresponding to the search node; The module M34 is used for updating the profit value and the simulation times of the searching node and the ancestor nodes thereof to increase the profit value of the searching node by one and increase the simulation times by one; a module M35, configured to repeat the modules M32 to M34 until the number of iterations reaches a preset threshold; The module M36 is used for calculating UCT values of all the child nodes of the Monte Carlo root node and selecting interactable events corresponding to the child node with the largest UCT value as a current interface; In the module M32, if the subsequent page jump set of the page corresponding to the current node is not empty and the pages in the subsequent page jump set are all children of the current node, calculating the UCT value of each child node, selecting the child node with the largest UCT value as the current node, continuing traversing the monte carlo tree until the subsequent page jump set of the current node is empty or there is a page which is not a child of the current node in the subsequent page jump set, if the subsequent page jump set of the current node is not empty, constructing the page which is not a child of the current node as a child of the current node, and selecting the constructed child node as a search node; In the module M33, taking a page corresponding to the search node as a current page, randomly selecting a subsequent page from a subsequent page jump set of the current page as the current page until the subsequent page jump set of the current page is empty, taking MINREWARD as a return value of the search node if the current page is not an interface of the UI application to be tested, otherwise taking maxReward as a return value of the search node, wherein MINREWARD is less than maxReward; The UCT value of the child node is calculated by adopting the following formula: UCT (V (i))=Q (V (i))/N (V (i))+c×sqrt (log (N (V))/N (V (i))), wherein, V (i) represents the ith child node of node V; UCT (V (i)) represents the UCT value of the ith child node of node V; Q (V (i)) represents the benefit value of the ith child node of node V; n (V (i)) represents the number of simulations of the ith child node of node V; N (V) is expressed as the number of simulations of node V; log is a logarithmic function; sqrt is a square root function; c is a preselected set coefficient.
- 5. The apparatus for UI application testing of claim 4, wherein said end condition is a test coverage greater than a first limit and a test time greater than a second limit, wherein test coverage = number of interactable events performed/total number of interactable events.
- 6. The apparatus for UI application testing of claim 4, In the module M1, when the interactable event of each control of the page is extracted through analysis of the layout information of the page control, the corresponding page information is found in the page information set through matching of the layout information of the page control, if the corresponding page information is not found in the page information set, the interactable event of each control of the page is extracted through analysis of the layout information of the page control, the page information is added into the page information set, and otherwise, the corresponding interactable event and the subsequent page skip set are extracted from the corresponding page information.
Description
UI application testing method and device Technical Field The invention relates to automatic testing of software functions, in particular to automatic testing of an interactive interface (UI). Background The software interactive interface test is a software system function test, and a large amount of manpower resources are often consumed. Accordingly, recently, automated testing is increasingly being adopted. In the prior art, the software interactive interface automatic test has two modes, namely a first machine is fully automatic exploration test, and a second is semi-automatic test, such as recording a test path during manual test, and then executing the recorded test path through the machine after regression test. The fully-automatic exploration test of the machine is widely paid attention to because of the fact that the labor is completely saved. However, in the prior art, the fully-automatic exploration test of the machine still has a plurality of technical problems, and one of the great problems is the problem of test efficiency. One of the main reasons for the inefficiency is that the test coverage rate and the test cases do not have the same ratio, specifically, a large stack of test cases is generated when the machine is automatically explored for testing, but the test cases may be usually all on the same test point, but the number of test cases generated by other test points needing to be tested is insufficient. Disclosure of Invention The invention aims to solve the problem that the testing efficiency is low when a machine automatically explores and tests. In order to solve the problems, the invention adopts the following scheme: A method of UI application testing according to the present invention comprises the steps of: step S1, loading and executing UI application to be tested, and selecting a currently-stayed interface as a current page; Step S2, judging whether the current page is an interface of the UI application to be tested, if the current page is not the interface of the UI application to be tested, re-executing the step S1, otherwise, extracting page control layout information of the current page, extracting interactable events of all controls of the page through analysis of the page control layout information to form an interactable event set of the current page, and extracting a subsequent page jump set of the current page through page matching; step S3, judging whether an unexecutable interactable event exists in the interactable event set of the current page through the subsequent page jump set of the current page, if so, randomly selecting an unexecutable interactable event, otherwise, searching for an interactable event through a Monte Carlo tree; Step S4, executing the selected interactable event, adding the page subjected to the jumping of the interactable event and the selected interactable event into a subsequent page jumping set of the current page, and simultaneously selecting the page subjected to the jumping as the current page to repeat the steps S2, S3 and S4 until the ending condition is met; the searching for an interactable event through the Monte Carlo tree comprises the following steps: S31, constructing a root node of a Monte Carlo tree by using a current page; step S32, performing traversal search on the Monte Carlo tree by taking the root node of the Monte Carlo tree as an initial current node to obtain a search node; step S33, calculating a return value of the search node by random walk of a subsequent page of the page corresponding to the search node; Step S34, updating the return value and the simulation times of the searching node and the ancestor nodes thereof to increase the return value of the searching node by one; step S35, repeating steps S32 to S34 until the iteration number reaches a preset threshold; Step S36, calculating UCT values of all the child nodes of the Monte Carlo root node, and selecting interactable events corresponding to the child node with the largest UCT value as a current interface; In the step S32, if the subsequent page jump set of the page corresponding to the current node is not empty and the pages in the subsequent page jump set are all children of the current node, the UCT value of each children node is calculated, the children node with the largest UCT value is selected as the current node to continue traversing the Monte Carlo tree until the subsequent page jump set of the current node is empty or the pages which are not children of the current node exist in the subsequent page jump set; in the step S33, a page corresponding to the search node is taken as a current page, and a subsequent page is randomly selected from a subsequent page jump set of the current page as the current page until the subsequent page jump set of the current page is empty, wherein MINREWARD is taken as a return value of the search node if the current page is not an interface of the UI application to be tested, or maxReward is taken as a return value