A test case path generation method, device, equipment and storage medium
Patent Information
- Application Number
- CN202110736526.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-30
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2041-06-30
AI Technical Summary
[0005]本申请实施例提供一种测试案例路径生成方法、装置、设备及计算机可读存储介质,以解决相关技术中采用单一方式生成的测试案例或多或少存在一些不足,导致自动化测试的测试效果较差的问题
通过获取待处理的时序图;时序图包含多个请求对象、对象传递的消息、对象间的调用关系;调用用于分析时序图的算法包,对多个请求对象、对象传递的消息和对象间的调用关系进行处理,构建时序图的有向图;即时序图转换成有向图时引入了用于分析时序图的算法包,便于对复杂的时序图进行快速分析处理以生成有向图;基于遗传和蚁群算法,将经过交叉和变异处理得到的多个种群对象,分配到有向图的多个请求对象的节点i和节点j上;基于迭代算法,从多个种群对象的每一种群对象找到的路径中,筛选出节点i和节点j之间的一条目标路径;将各个目标路径上各请求对象对应的对象传递的消息进行串联,生成场景测试案例路径;其中,场景测试案例路径用于从测试案例数据库中查找场景测试案例;即本申请将改进的遗传和蚁群算法融合算法应用于上述有向图,对相关技术中测试用例生成算法进行了改进,与单一方式生成测试案例相比,提高了算法的全局搜索能力,在每一次迭代过程中,对已有的种群对象路径进行选择、交叉和变异操作,提高种群对象路径的多样性;如此,解决了采用单一方式生成的测试案例或多或少存在一些不足,导致自动化测试的测试效果较差的问题,有效提升了自动化测试的效率和准确性。
Smart Images

Figure CN113392020B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology in financial technology (Fintech), and includes, but is not limited to, a test case path generation method, apparatus, device, and computer-readable storage medium. Background Technology
[0002] With the development of computer technology, more and more technologies are being applied in the financial field, and the traditional financial industry is gradually transforming into financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, Fintech also places higher demands on technology.
[0003] In the fintech sector, various application and system software play an irreplaceable role. Software quality has always been a hotly debated issue, and software testing serves as a crucial means of ensuring it.
[0004] In related technologies, there are three testing methods for automated testing: converting a time sequence graph into a directed graph, generating test cases using a genetic algorithm (GA), or generating test cases using an ant colony algorithm (ACA). However, test cases generated using a single method have some shortcomings, resulting in poor testing performance for automated testing. Summary of the Invention
[0005] This application provides a test case path generation method, apparatus, device, and computer-readable storage medium to address the problem that test cases generated using a single method in related technologies have some shortcomings, resulting in poor test performance in automated testing.
[0006] The technical solution of this application embodiment is implemented as follows:
[0007] This application provides a test case path generation method, including: Obtain the sequence diagram to be processed; the sequence diagram contains multiple request objects, messages passed between objects, and calling relationships between objects; The algorithm package used to analyze the sequence graph is invoked to process the multiple request objects, the messages passed by the objects, and the calling relationships between the objects, and to construct a directed graph of the sequence graph. Based on genetic and ant colony algorithms, multiple population objects obtained through crossover and mutation are assigned to nodes i and j of the multiple request objects in the directed graph. Based on the iterative algorithm, a target path between node i and node j is selected from the paths found by each of the multiple population objects. The messages passed by the objects corresponding to the request objects on each of the target paths are concatenated to generate a scenario test case path; wherein, the scenario test case path is used to search for scenario test cases from the test case database.
[0008] A test case path generation device, comprising: The acquisition module is used to acquire the sequence diagram to be processed; the sequence diagram includes multiple request objects, messages passed between objects, and calling relationships between objects. The processing module is used to call the algorithm package for analyzing the sequence graph, process the multiple request objects, the messages passed by the objects, and the calling relationships between the objects, and construct a directed graph of the sequence graph; The processing module is used to assign multiple population objects obtained through crossover and mutation processing to nodes i and j of the multiple request objects in the directed graph, based on genetic and ant colony algorithms. The processing module is used to select a target path between node i and node j from the paths found by each of the multiple population objects based on an iterative algorithm. The processing module is used to concatenate the messages passed by the objects corresponding to the request objects on each of the target paths to generate a scenario test case path; wherein, the scenario test case path is used to search for scenario test cases from the test case database.
[0009] This application provides a device, including: The memory is used to store executable instructions; the processor is used to implement the above method when executing the executable instructions stored in the memory.
[0010] This application provides a computer-readable storage medium storing executable instructions for implementing the above-described method when executed by a processor.
[0011] The embodiments of this application have the following beneficial effects: The process involves: acquiring a sequence graph to be processed; the sequence graph contains multiple request objects, messages passed between objects, and call relationships between objects; invoking an algorithm package for analyzing the sequence graph to process the multiple request objects, messages passed between objects, and call relationships between objects, and constructing a directed graph of the sequence graph; introducing an algorithm package for analyzing the sequence graph when converting the sequence graph into a directed graph facilitates rapid analysis and processing of complex sequence graphs to generate directed graphs; based on genetic and ant colony algorithms, multiple population objects obtained through crossover and mutation are assigned to nodes i and j of multiple request objects in the directed graph; based on an iterative algorithm, a target path between node i and node j is selected from the paths found by each population object; and the target paths are then... The messages passed by the objects corresponding to each request object on the path are concatenated to generate a scenario test case path. This scenario test case path is used to search for scenario test cases in the test case database. In other words, this application applies an improved genetic and ant colony algorithm fusion algorithm to the aforementioned directed graph, improving the test case generation algorithm in related technologies. Compared with a single method of test case generation, it enhances the algorithm's global search capability. In each iteration, it performs selection, crossover, and mutation operations on existing population object paths, increasing the diversity of population object paths. Thus, it solves the problem that test cases generated using a single method have some shortcomings, leading to poor testing results in automated testing, and effectively improves the efficiency and accuracy of automated testing. Attached Figure Description
[0012] Figure 1 This is a schematic diagram of an optional architecture of a terminal provided in an embodiment of this application; Figure 2 This is an optional flowchart illustrating the test case path generation method provided in the embodiments of this application; Figure 3 This is a schematic diagram of the timing diagram provided in the embodiments of this application; Figure 4 This is a schematic diagram of a directed graph provided in an embodiment of this application; Figure 5 This is a flowchart illustrating an implementable application scenario of the test case path generation method provided in this application embodiment. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] In the following description, references to "some embodiments" refer to a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same or different subsets of all possible embodiments and may be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art to which the embodiments of this application pertain. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit the application.
[0015] The following describes exemplary applications of the test case path generation device provided in this application. This device can be implemented as any terminal with a screen display function, such as a laptop, tablet, desktop computer, mobile device (e.g., mobile phone, portable music player, personal digital assistant, dedicated messaging device, portable gaming device), or intelligent robot, or as a server. The following will describe exemplary applications when the test case path generation device is implemented as a terminal.
[0016] See Figure 1 , Figure 1 This is a schematic diagram of the structure of the terminal 100 provided in the embodiments of this application. Figure 1 The terminal 100 shown includes at least one processor 110, at least one network interface 120, a user interface 130, and a memory 150. The various components in the terminal 100 are coupled together via a bus system 140. It is understood that the bus system 140 is used to implement communication between these components. In addition to a data bus, the bus system 140 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 1 The general labeled all buses as Bus System 140.
[0017] The processor 110 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0018] User interface 130 includes one or more output devices 131 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 130 also includes one or more input devices 132, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0019] Memory 150 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. Memory 150 may optionally include one or more storage devices physically located remote from processor 110. Memory 150 may include volatile memory or non-volatile memory, or both. Non-volatile memory may be read-only memory (ROM), and volatile memory may be random access memory (RAM). The memory 150 described in this application embodiment is intended to include any suitable type of memory. In some embodiments, memory 150 is capable of storing data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplarily described below.
[0020] Operating system 151 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks; The network communication module 152 is used to reach other computing devices via one or more (wired or wireless) network interfaces 120, such as Bluetooth, WiFi, and Universal Serial Bus (USB). The input processing module 153 is used to detect and translate one or more user inputs or interactions from one or more input devices 132.
[0021] In some embodiments, the apparatus provided in this application can be implemented in software. Figure 1 A test case path generation device 154 stored in memory 150 is shown. This test case path generation device 154 can be a test case path generation device in terminal 100, and can be software in the form of programs and plug-ins, including the following software modules: an acquisition module 1541 and a processing module 1542. These modules are logically linked and can therefore be arbitrarily combined or further divided according to their implemented functions. The functions of each module will be described below.
[0022] In other embodiments, the apparatus provided in this application can be implemented in hardware. For example, the apparatus provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the test case path generation method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0023] The test case path generation method provided in this application will be described below with reference to the exemplary application and implementation of the terminal 100 provided in the embodiments of this application. See also Figure 2 , Figure 2 This is an optional flowchart illustrating the test case path generation method provided in this application embodiment, which will be combined with... Figure 2 The steps shown are explained below. Step S201: Obtain the timing diagram to be processed.
[0024] The sequence diagram contains multiple request objects, messages passed between objects, and calling relationships between objects.
[0025] In this embodiment, the sequence diagram, also known as a sequence diagram or sequential diagram, is an interaction diagram using the Unified Modeling Language (UML). The sequence diagram displays the dynamic collaboration between multiple objects by describing the temporal order in which messages are sent between requesting objects.
[0026] For example, in combination Figure 3 As shown, a sequence diagram contains multiple request objects, messages passed between objects, and calling relationships between objects. The sequence diagram itself conveys information specific to a particular communication scenario. Among these, the multiple request objects include... Figure 3The objects shown are Object_A, Object_B, Object_C, Object_D, Object_E, WeChat, and QQ. The messages passed between these objects include messages exchanged between these multiple requesting objects. For example, the login message and return result message exchanged between Object_A and Object_B; the password verification (code) message and return result message exchanged between Object_B and WeChat; the code verification message and return result message exchanged between Object_B and QQ; the session creation message and session return message exchanged between Object_B and Object_E; the text message and return result message exchanged between Object_A and Object_D; the login status verification message and return result message exchanged between Object_D and Object_E; and the text message and return result message exchanged between Object_C and Object_D. The calling relationship between objects refers to the calling relationship between them when performing message passing. For example, when Object_A and Object_B exchange a login message, Object_A calls Object_B; another example is when Object_B and WeChat exchange a code verification message, Object_B calls WeChat.
[0027] Step S202: Call the algorithm package used to analyze the sequence graph, process multiple request objects, messages passed between objects, and call relationships between objects, and construct a directed graph of the sequence graph.
[0028] In this embodiment of the application, when a sequence diagram is obtained, it is converted into a directed graph. Here, an algorithm package for analyzing the sequence diagram is called to process multiple request objects, messages passed between objects, and call relationships between objects to construct a directed graph of the sequence diagram.
[0029] In a feasible scenario, the algorithm package used for analyzing time series graphs could be the graph theory (networkx) package in the computer programming language (Python). The networkx package is a software package written in Python used for creating, manipulating, and learning complex networks. Using networkx, networks can be stored in standardized and non-standardized data formats, various random and classic networks can be generated, network structures can be analyzed, network models can be built, new network algorithms can be designed, and networks can be drawn, enabling flexible processing of the objects to be processed.
[0030] For example, when using the networkx package to convert a sequence graph into a directed graph, the following code can be used as a reference: import networkx as nx #Creating a directed graph G = nx.DiGraph() #Directed edges in a directed graph edges=[("Object_A","Object_B"),("Object_B","WeChat"),("Object_B","QQ"),("Object_B","Object_E"),("Object_A","Object_D"),("Object_D","Object_C")] for edge in edges: G.add_edge(edge[0],edge[1]) pagerank_list=nx.pagerank(G, alpha=1) nx.draw_networkx(G) As shown in the code above, when creating a directed graph, firstly, the directed edges in the graph are defined; for example, a directed edge is defined from node Object_A to node Object_B, from node Object_B to node Wechat, from node Object_B to node QQ, from node Object_B to node Object_E, from node Object_A to node Object_D, and from node Object_D to node Object_C. Secondly, the nodes and the defined directed edges are read and added to the undirected graph G, thus obtaining the directed graph draw_networkx(G).
[0031] Based on the networkx algorithm package Figure 3 The timing diagram shown can be processed to obtain... Figure 4 The directed graph shown includes seven nodes: Object_A, Object_B, Object_C, Object_D, Object_E, Wechat, and QQ, as well as the directed paths between the nodes.
[0032] Step S203: Based on genetic and ant colony algorithms, the multiple population objects obtained after crossover and mutation are assigned to nodes i and j of multiple request objects in the directed graph.
[0033] In this application embodiment, the scheme of generating test cases based on a single GA algorithm or ACA algorithm is improved by proposing a new algorithm that combines the ideas of the two algorithms, namely, Genetic-ant Colony Algorithm (GACR). This algorithm improves the shortcomings of a single algorithm and complements each other's advantages. For example, when processing the directed graph obtained above based on Genetic-ant Colony Algorithm (GACR), crossover and mutation processing is first performed on the original population objects to complete the selection of individuals with high fitness in the original population objects, thereby improving the diversity of the population and ensuring that the GACR algorithm can effectively solve the problem of premature convergence when the search efficiency is low in the later stage.
[0034] In a feasible scenario, the GACR algorithm employs binary encoding. Its encoding set consists of a binary symbol set {0,1} composed of binary symbols 0 and 1, which corresponds to the computer's computational methods, and binary can represent various types of data. Therefore, this application's use of binary encoding for node identifiers and parameters can improve the algorithm's efficiency to some extent. Furthermore, using the most basic computational type in binary computers can effectively represent problems without numerical concepts.
[0035] During encoding, let the range of values for a certain parameter be [ This application uses a length of [length missing]. If the parameter is represented by binary encoded symbols, then it will generate a total of The correspondence between different encodings and parameter encoding is as follows:
[0036]
[0037]
[0038] …
[0039] in, .
[0040] Therefore, correspondingly, during decoding, assuming the encoding of a certain individual is ( Then the corresponding decoding formula is:
[0041] For example, parameters are provided. Currently, 6-bit binary encoding is used. After encoding, the total number is The accuracy of obtaining the optimal solution is The range of binary to decimal is... , switch to The interval can be solved using the decoding formula above.
[0042] In other words, this application, based on genetic and ant colony algorithms, assigns multiple population objects obtained through crossover and mutation to nodes i and j, which are obtained by encoding the node identifiers of multiple request objects in a directed graph, in order to perform optimal path search. Node i and node j are two different nodes in the directed graph.
[0043] Step S204: Based on the iterative algorithm, select a target path between node i and node j from the paths found by each of the multiple population objects.
[0044] In this embodiment of the application, based on an iterative algorithm, in the process of selecting a target path between node i and node j from the paths found by each of the multiple population objects, the iteration stops when no shorter new path is generated, thus completing the selection of the target path.
[0045] Step S205: Concatenate the messages passed by the objects corresponding to each request object on each target path to generate the scenario test case path.
[0046] The scenario test case path is used to find scenario test cases from the test case database.
[0047] In this embodiment of the application, the test case database may be a database existing in the TCTP test knowledge graph platform.
[0048] Here, given a target path between each node, the messages passed by the objects corresponding to each request object on each target path are concatenated to generate a scenario test case path. This allows the scenario test case to be retrieved from the test case database of the TCTP test knowledge graph platform based on the scenario test case path, so as to execute automated testing.
[0049] The test case path generation method provided in this application obtains a sequence graph to be processed. The sequence graph contains multiple request objects, messages passed between objects, and call relationships between objects. An algorithm package for analyzing the sequence graph is invoked to process the multiple request objects, messages passed between objects, and call relationships between objects, constructing a directed graph of the sequence graph. When converting the sequence graph into a directed graph, an algorithm package for analyzing the sequence graph is introduced to facilitate rapid analysis and processing of complex sequence graphs to generate directed graphs. Based on genetic and ant colony algorithms, multiple population objects obtained through crossover and mutation are assigned to nodes i and j of multiple request objects in the directed graph. Based on an iterative algorithm, a target path between nodes i and j is selected from the paths found by each population object. The path; the messages passed by the objects corresponding to each request object on each target path are concatenated to generate a scenario test case path; wherein, the scenario test case path is used to find scenario test cases from the test case database; that is, this application applies the improved genetic and ant colony algorithm fusion algorithm to the above-mentioned directed graph, which improves the test case generation algorithm in related technologies. Compared with the single method of generating test cases, it improves the global search capability of the algorithm. In each iteration, the existing population object paths are selected, crossover, and mutated to improve the diversity of population object paths; thus, it solves the problem that test cases generated by the single method have some shortcomings, resulting in poor test results of automated testing, and effectively improves the efficiency and accuracy of automated testing.
[0050] In other embodiments of this application, see Figure 5 As shown, after obtaining the input timing diagram in step S301, step S302 is executed, which imports the Python networkx algorithm package. Figure 3 The timing diagram shown is processed, and in step S303, the output is... Figure 4 The directed graph is shown. Next, step S304 can be executed to traverse the directed graph using the GACR algorithm, followed by step S305 to generate scenario test case paths. Finally, step S306 is executed to find scenario test cases from the TCTP test knowledge graph platform based on these path and execute the scenario test cases. Of course, the output in step S303... Figure 4After generating the directed graph, step S307 can be executed to input the output directed graph into the TCTP knowledge graph platform. Upon receiving the tags (i.e., the messages transmitted by the request objects) of each node in the directed graph, the platform identifies the tags stored in the test case library for the request object and then executes step S306 to push the corresponding tag's test case to the TCTP test knowledge graph platform for readiness, awaiting the execution of the scenario test case. In other words, this application also uses the method of identifying the tags in the directed graph to obtain the pushed test cases with the corresponding tags from the TCTP test knowledge graph platform, and then executes the test cases.
[0051] In some embodiments, step S204, based on an iterative algorithm, selects a target path between node i and node j from the paths found by each of the multiple population objects. This can be achieved through the following steps: A11, calculate the probability that a population object at node i will visit node j. , , ,
[0052] in, Represents a node With nodes The concentration of pheromones along the link path between them Represents a node With nodes distance, Indicates the importance of the link path trajectory. The importance of visibility in indicating pheromone concentration. Indicates the number of objects in the population.
[0053] For example, if k1=5, k2=0.6, k3=3, k4=2, then, , At this point, as a control parameter for measuring the importance of pheromones, better path search results can be achieved.
[0054] Here, pheromones refer to a chemical substance secreted by ants during movement. Ants can sense this substance and determine its concentration, thus guiding them to move towards areas with higher pheromone intensity.
[0055] During the research on automated testing, the applicant discovered that the ACA algorithm suffers from insufficient pheromone in its initial stages, making it prone to getting trapped in local optima. Therefore, the GACR algorithm was proposed to address the issue of ACA... The heuristic parameters use a hybrid approach, meaning that the parameters are different for each individual parameter, in order to better leverage the advantages of the ACA algorithm.
[0056] A12, based on probability Determine the m1 paths found by each of the multiple population objects after the Mth iteration.
[0057] Where M is a positive integer.
[0058] In this embodiment, A12 is based on probability. To determine the m1 paths found by each of the multiple population objects after the Mth iteration, the following steps can be taken: Determine the probability. The paths from node i to node j that satisfy the probability threshold range are the m1 paths found by each of the multiple population objects after the Mth iteration. Here, when performing path optimization through population objects, we can... It determines the path that the population objects choose to take.
[0059] A13, based on an iterative algorithm, select the target path between node i and node j from m1 paths.
[0060] In some embodiments, A13 selects the target path between node i and node j from m1 paths based on an iterative algorithm, which can be achieved through the following steps: A131: Select m2 ordered paths from m1 paths that meet the path length condition.
[0061] Among them, the length of the remaining paths in the m1 paths is greater than the length of the ordered m2 paths; the length of the path that is first in the order of the m2 paths is less than the length of the path that is last in the order.
[0062] In this embodiment, satisfying the path length condition includes the path length occupying the top X% in the path set, for example, 20%. Of course, satisfying the path length condition can also include the path length being greater than a preset path length. That is, in each iteration that yields multiple paths, the paths found for each population object are filtered according to their path length; for example, only the top 20% of individuals are allowed to leave pheromones.
[0063] In some embodiments, the path ranking factor of the first path in the m2 ordered paths is greater than the path ranking factor of the last path.
[0064] In this embodiment, A12 is based on probability. To determine the m1 paths found by each of the multiple population objects after the Mth iteration, the following steps can also be taken: determine the probability. The paths that satisfy the probability threshold range and whose path ranking factors from node i to node j satisfy the ranking factor range are the m1 paths found by each of the multiple population objects after the Mth iteration. Here, when performing path optimization through population objects, a path ranking factor is introduced to change the weight of the path, and then the introduction of the path ranking factor and... Together they determine the path chosen by the population; for example, the larger the path ranking factor and... The larger the value, the greater the likelihood that the population will choose that path; moreover, even if one individual happens to discover a better path, this better path can be promoted more smoothly with the help of the path ranking factor, ensuring that the better path is not suppressed.
[0065] In this embodiment, the pheromone update rule is optimized to be better than the behavior of the natural ACA algorithm. The GACR algorithm improves upon the pheromone update rule and population dynamics of the traditional ACA algorithm. The parameters were optimized by sorting the path lengths found by each individual in ascending order, allowing only the top 20% of individuals to retain pheromones. Furthermore, for each path, the weight was set inversely proportional to its length and multiplied by a factor that decreases linearly with ranking (i.e., the path ranking factor). The ranking factor for the first-place path was 1, decreasing to 0 for the top 20%. To prevent the optimal path from being forgotten, if the first-place path in this iteration performs worse than the currently discovered optimal path, the optimal path is still ranked first as an individual, and the rankings of other individuals are adjusted accordingly, retaining pheromones according to the above rules. This ensures that the optimal path is not forgotten before being surpassed by a better path. Simultaneously, the introduction of the path ranking factor increases the influence of those who discover better paths.
[0066] A132, based on probability Determine the m3 paths found by each of the multiple population objects after the (M+1)th iteration.
[0067] It should be noted that A132 is based on probability. Determine m3 paths and their probability-based connections in A12 above. The implementation method for determining m1 paths is the same.
[0068] A133. If the shortest path among m3 paths is greater than the shortest path among m2 paths, select m4 ordered paths from the m3 paths that satisfy the path length condition.
[0069] A134: Insert the shortest path from the m2 ordered paths before the shortest path from the m4 ordered paths to obtain the ordered paths after the (M+1)th iteration.
[0070] A135, select the target path from the ordered path after the (M+1)th iteration.
[0071] In some embodiments, the path ranking factor of the shortest path among the m2 ordered paths is greater than the path ranking factor of the shortest path among the m4 ordered paths. The target path selected above is the shortest path among the ordered paths after the (M+1)th iteration.
[0072] Here, N represents the number of individuals. Taking 50 individuals as an example, parameters for 50 individuals are randomly generated in each iteration, traversing the meaningful parameter space as much as possible. If more than half of the individuals in the entire population are stuck on a suboptimal path, and one individual happens to discover a better path, according to traditional rules, it only has 1 / 50 of the say. According to the path ranking factor rule, the weight of the top 10 individuals decreases linearly, with the first individual having approximately 1 / 5 of the say. This allows advanced experiences to be promoted more smoothly, while outdated experiences are less likely to form self-locking and suppress the generation of advanced experiences. Thus, it increases the probability of local convergence and improves the algorithm's global search capability.
[0073] In other words, during the iteration process, as long as the next iteration produces a new path that is shorter than the path obtained in the previous iteration, the iteration continues. At the same time, the path ranking factor of the shortest path is always the largest, thus ensuring that a better path can be found.
[0074] In some embodiments, A135 selects the target path from the ordered path arrangement after the (M+1)th iteration, which can be achieved through the following steps: A13511, based on probability Determine the m4 paths found by each of the multiple population objects after the M+2th iteration.
[0075] It should be noted that A13511 is based on probability. Determine m4 paths and their probability-based relationships in A12 above. The implementation method for determining m1 paths is the same.
[0076] A13512. If the path length of any of the m4 paths is greater than the ordered path after the (M+1)th iteration, stop the iteration and select the target path from the ordered path after the (M+1)th iteration.
[0077] In this embodiment of the application, if the path obtained by iteration cannot update the original path, it means that all optimal solutions have been found, so the iteration stops, and the target path is selected from the multiple candidate paths arranged in an ordered manner.
[0078] In some embodiments, A135 can select the target path from the ordered path arrangement after the (M+1)th iteration, which can also be achieved through the following steps: A13521, based on probability Determine the m4 paths found by each of the multiple population objects after the M+2th iteration.
[0079] It should be noted that A13521 is based on probability. Determine m4 paths and their probability-based relationships in A12 above. The implementation method for determining m1 paths is the same.
[0080] A13522, if among the m4 paths there exists a path smaller than the ordered path after the (M+1)th iteration, the aforementioned target path exists.
[0081] A13523, insert the target path before the shortest path in the ordered path after the (M+1)th iteration to obtain the ordered path after the (M+2)th iteration.
[0082] Here, the path ranking factor of the shortest path in the ordered arrangement of paths after the (M+2)th iteration is greater than the path ranking factor of the shortest path in the ordered arrangement of paths after the (M+1)th iteration.
[0083] In other words, during the iterative process, as long as a new shortest path is found in a new round, the new shortest path is prioritized, thus preventing a large portion of the population from getting stuck on a suboptimal path.
[0084] A13524, selects the target path from the ordered path after the (M+2)th iteration.
[0085] In some embodiments, multiple population objects obtained through crossover and mutation processing in step S203 can also be obtained through the following steps: B11 selects the paired population objects M1 and M2 from the original multiple population objects.
[0086] B12, cross-pollinate the corresponding genes in population objects M1 and M2 to obtain the target population object M. ’ 1 and target population object M ’ 2.
[0087] B13, based on the set mutation rate, for the target population object M ’ Invert the gene values at the random mutation points of 1, and apply this to the target population M. ’ Invert the gene values at the random mutation points of 2 to obtain multiple population objects after crossover and mutation processing.
[0088] Compared with the standard GA algorithm, the GACR algorithm provided in this application has made the following two improvements, which aim to optimize the problem of premature convergence of the GA algorithm due to the reduction of test case diversity during the iteration of the GA algorithm.
[0089] First point: Cross-operation GACR employs an improved crossover operation. The specific design is as follows: The selection of paired population objects M1 and M2 from B11 above can be achieved through the following steps: pairing parent individuals according to the principle of "matching social status", that is, sorting the parent individuals by fitness function value, pairing those with smaller fitness functions with those with smaller fitness functions, and pairing those with larger fitness functions with those with larger fitness functions.
[0090] The crossover of genes between paired populations in B12 can be achieved through the following steps: using chaotic sequences to determine the crossover position, and then performing crossover on the determined crossover terms.
[0091] For example, in a pairing of (M1, M2), their individuals are respectively... , (n represents the number of target nodes), using chaotic sequences (Logistics). To generate a positive integer between 2 and n, the specific steps are as follows: Take a random initial value (0,1), and then use... Each iteration generates a chaotic value at (0,1). This chaotic value is saved as the chaotic iteration value for generating the next generation of crossover terms. This value is then multiplied by 100 and added to by 2, and the final value is taken as an integer. If this number is 33, then crossover is performed on the corresponding genes in individuals (M1, M2) to obtain a new individual (M... ’ 1,M ’ 2).
[0092] It is clear that this single-point crossover has a very small impact on the original solution, which can reduce and avoid the chattering problem that occurs in combinatorial optimization applications of the GA algorithm, and can improve the convergence accuracy of the algorithm.
[0093] Second point: Mutation operation Mutation is also a means of achieving population diversity and an important guarantee for escaping local optima and finding global optimization. The specific mutation operator design of this patent is as follows: First, by setting the mutation rate to be inversely proportional to the fitness value, the different contributions of individuals to the algorithm's evolution are determined, ensuring survival of the fittest and allowing superior individuals to be passed on to the next generation. The mutation rate in B13 above can be set as follows. To avoid the mutation operator disrupting the pattern, the mutation rate is generally required to be very low (less than 0.1) during algorithm execution. Especially for superior individuals, it is necessary to further reduce the mutation rate to increase their chances of survival. The following formula is the expression for the mutation rate:
[0094] in, For the corresponding fitness function value, This is the coefficient of variation.
[0095] By selecting individuals based on calculated fitness values, the blind selection of data is avoided.
[0096] Furthermore, in B13, inverting the gene value at a random mutation point can be achieved through the following steps: Based on the mutation rate, randomly select two integers between 2 and n, and mutate the genes at the positions corresponding to these two numbers. The basic bit mutation method is used for the mutation operation. The table below shows the randomly generated mutation point positions (where the numbers indicate where the mutation point is located at the gene locus). Then, according to the mutation rate, the original gene value of the mutation point is inverted to obtain the new gene value after mutation, thus obtaining new individuals and achieving population diversity.
[0097]
[0098] Table 1 Examples of Mutation Operations Further explanation of Table 1 follows. For example, for individual object number 1, the fourth locus from left to right in the crossover result (011001) is selected as the mutation point, and the result is inverted, resulting in 011101, meaning the fourth locus changes from 0 to 1. Similarly, for individual object number 2, the fifth locus from left to right in the crossover result (111101) is selected as the mutation point, and the result is inverted, resulting in 111111, meaning the fifth locus changes from 1 to 0. The GACR algorithm provided in this application performs crossover and mutation operations on individuals, making the search process more flexible, increasing the global test path search capability, and improving test case set coverage.
[0099] The following continues to describe the exemplary structure of the test case path generation device 154 provided in the embodiments of this application as a software module. In some embodiments, such as Figure 1As shown, the software module stored in the test case path generation device 154 in the memory 150 can be the test case path generation device in the terminal 100, including: The acquisition module 1541 is used to acquire the sequence diagram to be processed; the sequence diagram contains multiple request objects, messages passed between objects, and calling relationships between objects. Processing module 1542 is used to call the algorithm package for analyzing sequence diagrams, process multiple request objects, messages passed between objects, and call relationships between objects, and construct a directed graph of the sequence diagram; The processing module 1542 is used to assign multiple population objects obtained through crossover and mutation processing to nodes i and j of multiple request objects in a directed graph based on genetic and ant colony algorithms. Processing module 1542 is used to filter out a target path between node i and node j from the paths found by each of the multiple population objects based on an iterative algorithm. The processing module 1542 is used to concatenate the messages passed by the objects corresponding to the request objects on each target path to generate a scenario test case path; wherein, the scenario test case path is used to search for scenario test cases from the test case database.
[0100] In some embodiments, the processing module 1542 is configured to calculate the probability that a population object at node i will access node j. , , ,
[0101] in, Represents a node With nodes The concentration of pheromones along the link path between them Represents a node With nodes distance, Indicates the importance of the link path trajectory. The importance of visibility in indicating pheromone concentration. Indicates the number of objects in the population; Based on probability Let m1 paths be found by each of the multiple population objects after the Mth iteration; where M is a positive integer. The target path between node i and node j is selected from m1 paths using an iterative algorithm.
[0102] In some embodiments, the processing module 1542 is configured to filter out m2 ordered paths from m1 paths that satisfy the path length condition; wherein the length of the remaining paths in the m1 paths is greater than the length of the ordered paths in the m2 paths; and the path length of the first ordered path in the m2 ordered paths is less than the path length of the last ordered path; based on probability... After the (M+1)th iteration, determine the m3 paths found by each of the multiple population objects; if the shortest path among the m3 paths is greater than the shortest path among the m2 paths, select m4 ordered paths from the m3 paths that satisfy the path length condition; insert the shortest path among the m2 ordered paths before the shortest path of the m4 ordered paths to obtain the ordered paths after the (M+1)th iteration; select the target path from the ordered paths after the (M+1)th iteration.
[0103] In some embodiments, the path ranking factor of the first path in the m2 ordered paths is greater than the path ranking factor of the second path; the path ranking factor of the shortest path in the m2 ordered paths is greater than the path ranking factor of the shortest path in the m4 ordered paths.
[0104] In some embodiments, the processing module 1542 is configured to base its processing on probability. Determine the m4 paths found by each of the multiple population objects after the M+2th iteration; if the path length of any of the m4 paths is greater than the ordered path after the M+1th iteration, stop the iteration, and select the target path from the ordered path after the M+1th iteration.
[0105] In some embodiments, the processing module 1542 is configured to: if there is a target path among the m4 paths that is less than the shortest path in the ordered arrangement of paths after the (M+1)th iteration; insert the target path before the shortest path in the ordered arrangement of paths after the (M+1)th iteration to obtain the ordered arrangement of paths after the (M+2)th iteration; if the path ranking factor of the shortest path in the ordered arrangement of paths after the (M+2)th iteration is greater than the path ranking factor of the shortest path in the ordered arrangement of paths after the (M+1)th iteration; and select the target path from the ordered arrangement of paths after the (M+2)th iteration.
[0106] In some embodiments, the processing module 1542 is configured to select paired population objects M1 and M2 from the original multiple population objects; and to perform crossover on the corresponding genes in population objects M1 and M2 to obtain the target population object M. ’ 1 and target population object M ’ 2; Based on the set mutation rate, for the target population object M ’Invert the gene values at the random mutation points of 1, and apply this to the target population M. ’ Invert the gene values at the random mutation points of 2 to obtain multiple population objects after crossover and mutation processing.
[0107] The test case path generation device provided in this application obtains a sequence graph to be processed. The sequence graph contains multiple request objects, messages passed between objects, and call relationships between objects. An algorithm package for analyzing the sequence graph is invoked to process the multiple request objects, messages passed between objects, and call relationships between objects, constructing a directed graph of the sequence graph. When converting the sequence graph into a directed graph, an algorithm package for analyzing the sequence graph is introduced, facilitating rapid analysis and processing of complex sequence graphs to generate directed graphs. Based on genetic and ant colony algorithms, multiple population objects obtained through crossover and mutation are assigned to nodes i and j of multiple request objects in the directed graph. Based on an iterative algorithm, a target path between nodes i and j is selected from the paths found by each population object. The path; the messages passed by the objects corresponding to each request object on each target path are concatenated to generate a scenario test case path; wherein, the scenario test case path is used to find scenario test cases from the test case database; that is, this application applies the improved genetic and ant colony algorithm fusion algorithm to the above-mentioned directed graph, which improves the test case generation algorithm in related technologies. Compared with the single method of generating test cases, it improves the global search capability of the algorithm. In each iteration, the existing population object paths are selected, crossover, and mutated to improve the diversity of population object paths; thus, it solves the problem that test cases generated by the single method have some shortcomings, resulting in poor test results of automated testing, and effectively improves the efficiency and accuracy of automated testing.
[0108] It should be noted that the description of the apparatus in this application embodiment is similar to the description of the method embodiment described above, and has similar beneficial effects as the method embodiment; therefore, it will not be repeated. For technical details not disclosed in this apparatus embodiment, please refer to the description of the method embodiment of this application for understanding.
[0109] This application provides a storage medium storing executable instructions. When these executable instructions are executed by a processor, they cause the processor to perform the method provided in this application, for example... Figure 2 The method shown.
[0110] In some embodiments, the storage medium may be a computer-readable storage medium, such as a ferromagnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), flash memory, magnetic surface memory, optical disc, or a compact disk-read-only memory (CD-ROM); or it may be a device that includes one or any combination of the above-mentioned memories.
[0111] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0112] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file containing other programs or data, for example, in one or more scripts within a Hyper Text Markup Language (HTL) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files storing one or more modules, subroutines, or code sections). As an example, executable instructions may be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.
[0113] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A method for generating test case paths, characterized in that, include: Obtain the sequence diagram to be processed; the sequence diagram contains multiple request objects, messages passed between objects, and calling relationships between objects; The algorithm package used to analyze the sequence graph is invoked to process the multiple request objects, the messages passed by the objects, and the calling relationships between the objects, and to construct a directed graph of the sequence graph. Based on genetic and ant colony algorithms, multiple population objects obtained through crossover and mutation are assigned to nodes i and j of the multiple request objects in the directed graph. Based on the iterative algorithm, a target path between node i and node j is selected from the paths found by each of the multiple population objects. The messages passed by the objects corresponding to each request object on each of the target paths are concatenated to generate a scenario test case path; wherein, the scenario test case path is used to search for scenario test cases from the test case database; The step of selecting a target path between node i and node j from the paths found by each of the multiple population objects based on an iterative algorithm includes: Calculate the probability that a population object at node i will visit node j. , , , in, Represents the node With the node The concentration of pheromones along the link path between them Represents the node With the node distance, This indicates the importance of the trajectory of the link path. The visibility of the pheromone concentration indicates its importance. Indicates the number of objects in the population; k1, k2, k3, and k4 are all positive numbers; Based on the probability Determine the m1 paths found by each of the multiple population objects after the Mth iteration; where M is a positive integer; Based on the iterative algorithm, the target path between node i and node j is selected from the m1 paths, including: selecting m2 ordered paths from the m1 paths that satisfy the path length condition; wherein the length of the remaining paths in the m1 paths is greater than the length of the ordered m2 paths; and the path length of the first ordered path in the m2 ordered paths is less than the path length of the last ordered path; based on the probability... After the (M+1)th iteration, determine the m3 paths found by each of the multiple population objects; if the shortest path among the m3 paths is greater than the shortest path among the m2 ordered paths, select m4 ordered paths from the m3 paths that satisfy the path length condition; insert the shortest path among the m2 ordered paths before the shortest path of the m4 ordered paths to obtain the ordered paths after the (M+1)th iteration; select the target path from the ordered paths after the (M+1)th iteration.
2. The method according to claim 1, characterized in that, The path ranking factor of the first path in the m2 ordered paths is greater than the path ranking factor of the second path; the path ranking factor of the shortest path in the m2 ordered paths is greater than the path ranking factor of the shortest path in the m4 ordered paths.
3. The method according to claim 1, characterized in that, The step of selecting the target path from the ordered paths after the (M+1)th iteration includes: Based on the probability Determine the m4 ordered paths found by each of the multiple population objects after the (M+2)th iteration; If the path length of any one of the m4 ordered paths is greater than the ordered path after the (M+1)th iteration, the iteration stops, and the target path is selected from the ordered path after the (M+1)th iteration.
4. The method according to claim 3, characterized in that, The method further includes: If there is a target path in the m4 ordered paths that is smaller than the target path in the ordered paths after the (M+1)th iteration; The target path is inserted before the shortest path in the ordered path after the (M+1)th iteration to obtain the ordered path after the (M+2)th iteration; the path ranking factor of the shortest path in the ordered path after the (M+2)th iteration is greater than the path ranking factor of the shortest path in the ordered path after the (M+1)th iteration. The target path is selected from the ordered paths after the (M+2)th iteration.
5. The method according to any one of claims 1 to 4, characterized in that, Before assigning the multiple population objects obtained through crossover and mutation processing to nodes i and j of the multiple requesting objects in the directed graph, the method based on genetic and ant colony algorithms includes: Select paired population objects M1 and M2 from the original multiple population objects; Cross-polating the corresponding genes in population objects M1 and M2 to obtain the target population object M. ’ 1 and target population object M ’ 2; Based on the set mutation rate, the target population object M... ’ Invert the gene values at the random mutation points of 1, and apply this to the target population object M. ’ The gene values at the random mutation points of 2 are inverted to obtain multiple population objects obtained through crossover and mutation processing.
6. A test case path generation device, characterized in that, For performing the method according to any one of claims 1 to 5, comprising: The acquisition module is used to acquire the sequence diagram to be processed; the sequence diagram includes multiple request objects, messages passed between objects, and calling relationships between objects. The processing module is used to call the algorithm package for analyzing the sequence graph, process the multiple request objects, the messages passed by the objects, and the calling relationships between the objects, and construct a directed graph of the sequence graph; The processing module is used to assign multiple population objects obtained through crossover and mutation processing to nodes i and j of the multiple request objects in the directed graph, based on genetic and ant colony algorithms. The processing module is used to select a target path between node i and node j from the paths found by each of the multiple population objects based on an iterative algorithm. The processing module is used to concatenate the messages passed by the objects corresponding to the request objects on each of the target paths to generate a scenario test case path; wherein, the scenario test case path is used to search for scenario test cases from the test case database.
7. A test case path generation device, characterized in that, include: Memory, used to store executable instructions; A processor, when executing executable instructions stored in the memory, implements the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, It stores executable instructions for causing a processor to execute, thereby implementing the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for detecting temporal constraint conflict
CN101877014A
UML sequence diagram-based test case automatic generation method
CN106951368A