Test path generation method based on maximum contribution times
By searching for loops in the state machine diagram and calculating the number of node occurrences, the test path is generated, and the problems of insufficient and redundant paths in the prior art are solved, thereby achieving maximum coverage of the state machine diagram and improving the test efficiency.
Patent Information
- Application Number
- CN202510166425.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-14
- Publication Date
- 2025-06-06
AI Technical Summary
The prior art cannot generate detailed test paths in a state diagram with multiple loops, resulting in test cases failing to fully cover some transfers in the state diagram, causing the problem of insufficient testing, and at the same time, a large number of redundant test paths increase test costs and reduce efficiency.
The test path generation method based on the maximum contribution times is adopted. All loops are searched and recorded through the system's state machine diagram, and the maximum number of times each node appears in the loop is calculated. If the traversal state machine diagram encounters the loop, the maximum number of times the node appears in the loop is traversal, thereby generating all test paths.
Maximize coverage of the state machine graph with multiple loops and minimize the number of traversal loops. The generated test path is more comprehensive, avoiding the generation of redundant test paths, reducing test costs and improving testing efficiency.
Smart Images

Figure CN120104479A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a test path generation method based on maximum contribution times, belonging to the field of system testing. Background Art
[0002] In system testing, when the object under test has multiple states, it is necessary to use state machine diagram-based testing in order to discover errors related to the object state. The general process of state machine diagram-based testing is to generate test cases based on the test requirements of the system. The so-called test requirements can be understood as the test coverage standards to be achieved by the test. In the test based on the UML state diagram, it is required that the test should cover all states and transitions between states. The generated test cases consist of test sequences and test data. For all test cases, a transition from the initial state to the specified state should be completed.
[0003] Generating test cases based on state machine diagrams is one of the research hotspots in the testing field. State coverage criteria and transition coverage criteria are basic test criteria based on state diagram testing. Different test criteria have different abilities to discover defects. However, the above two types of criteria cannot generate exhaustive test paths in state diagrams with multiple loops, resulting in the generated test cases not covering some transitions in the state diagram, thus causing the problem of insufficient testing. In addition, if full path coverage of the state diagram is achieved, a large number of test paths will be generated, among which some transitions will be repeatedly tested, resulting in increased testing costs and reduced testing efficiency. Summary of the invention
[0004] The technical problem solved by the present invention is: to overcome the shortcomings of the prior art and provide a test path generation method based on the maximum contribution number, which can realize the automatic generation of test paths for a state machine diagram with multiple loops, and the generated test paths can achieve maximum coverage of the state machine diagram and minimize the number of traversal cycles.
[0005] The technical solution of the present invention is: in a first aspect, a test path generation method based on the maximum contribution number is proposed, comprising:
[0006] Search and record all loops through all nodes and edges in the system's state machine graph;
[0007] According to all the loops searched, calculate the number of times each node appears in the loop, and record the maximum number of times a node appears in the loop;
[0008] Traverse the state machine graph. If a loop is encountered, traverse the maximum number of times the node appears in the loop to obtain all test paths.
[0009] Preferably, all loops are searched and recorded through all nodes and edges in the state machine graph of the system, specifically:
[0010] S1-1 parses all nodes and edges from the state machine diagram;
[0011] S1-2 records the initial node and the terminal node of the state machine diagram from all nodes and edges;
[0012] S1-3 deeply traverses the initial node of the state machine graph, records the nodes and edges visited during the deep traversal, and records the node being visited during the process as the current node;
[0013] S1-4 visits the neighboring node of the current node. If the neighboring node has been visited, a loop is obtained and the information of the loop is recorded;
[0014] S1-5 returns to step S1-3 and iterates again until the terminal node is visited.
[0015] Preferably, the method of recording the initial node and the terminal node of the state machine diagram from all nodes and edges is:
[0016] Iterate through all nodes:
[0017] If the current node does not belong to the starting point of any edge, it is considered to be a terminal node;
[0018] If the current node is not the end point of any edge, it is considered to be the initial node.
[0019] Preferably, the state machine diagram is traversed, and if a loop is encountered, the maximum number of times the node appears in the loop is traversed to obtain all test paths, specifically:
[0020] S2-1 deeply traverses the state machine graph starting from the initial node;
[0021] S2-2 determines whether the depth traversal is finished based on the current access node. If the traversal is not finished, the current access node and the visited path are marked, and the number of visits to the current node is recorded; if the traversal is finished, the path generation is terminated;
[0022] S2-3 judges the current node:
[0023] If the current node is the terminal node in the state machine diagram, it is considered that a test path is found and the test path is recorded. After the recording is completed, return to S2-1 and traverse again;
[0024] If the number of visits to the current node is less than or equal to the maximum count of the node, return to S2-1 and traverse again.
[0025] Preferably, whether the depth traversal is finished is determined based on the current access node, specifically:
[0026] If the current node has no unvisited adjacent nodes, and after backtracking to the previous node, the previous node has no unvisited adjacent nodes, and finally backtracking to the initial node and all the adjacent nodes of the initial node have been visited, the depth traversal ends.
[0027] In the second aspect, a test path generation system based on the maximum contribution number is proposed, including: a loop search module and a test path automatic generation module; wherein:
[0028] The loop search module searches and records all loops through all nodes and edges in the state machine graph of the system, and outputs all recorded node information and loop information to the test path automatic generation module;
[0029] The test path automatic generation module calculates the number of times each node appears in the loop based on all the searched loops, and records the maximum number of times the node appears in the loop; it traverses the state machine diagram, and if a loop is encountered, it traverses the maximum number of times the node appears in the loop, thereby obtaining all test paths.
[0030] Preferably, the loop search module searches and records all loops through all nodes and edges in the state machine graph of the system, specifically:
[0031] S1-1 parses all nodes and edges from the state machine diagram;
[0032] S1-2 records the initial node and the terminal node of the state machine diagram from all nodes and edges;
[0033] S1-3 deeply traverses the initial node of the state machine graph, records the nodes and edges visited during the deep traversal, and records the node being visited during the process as the current node;
[0034] S1-4 visits the neighboring node of the current node. If the neighboring node has been visited, a loop is obtained and the information of the loop is recorded;
[0035] S1-5 returns to step S1-3 and iterates again until the terminal node is visited.
[0036] Preferably, in the loop search module, the method of recording the initial node and the terminal node of the state machine diagram from all nodes and edges is:
[0037] Iterate through all nodes:
[0038] If the current node does not belong to the starting point of any edge, it is considered to be a terminal node;
[0039] If the current node is not the end point of any edge, it is considered to be the initial node.
[0040] Preferably, in the test path automatic generation module, the state machine diagram is traversed, and if a loop is encountered, the maximum number of times the node appears in the loop is traversed to obtain all test paths, specifically:
[0041] S2-1 deeply traverses the state machine graph starting from the initial node;
[0042] S2-2 determines whether the depth traversal is finished based on the current access node. If the traversal is not finished, the current access node and the visited path are marked, and the number of visits to the current node is recorded; if the traversal is finished, the path generation is terminated;
[0043] S2-3 judges the current node:
[0044] If the current node is the terminal node in the state machine diagram, it is considered that a test path is found and the test path is recorded. After the recording is completed, return to S2-1 and traverse again;
[0045] If the number of visits to the current node is less than or equal to the maximum count of the node, return to S2-1 and traverse again.
[0046] Preferably, in the test path automatic generation module, whether the deep traversal is finished is determined based on the current access node, specifically:
[0047] If the current node has no unvisited adjacent nodes, and after backtracking to the previous node, the previous node has no unvisited adjacent nodes, and finally backtracking to the initial node and all the adjacent nodes of the initial node have been visited, the depth traversal ends.
[0048] Compared with the prior art, the present invention has the following advantages:
[0049] (1) The present invention aims to solve the problem that a state graph with multiple loops cannot generate exhaustive test paths, resulting in incomplete coverage of test cases. A test path generation method based on the maximum contribution number is proposed. In a state graph with multiple loops, a more comprehensive test path can be generated to ensure full coverage of the system state space. The comprehensiveness of test case generation is improved. At the same time, by optimizing the test path selection, the generation of a large number of redundant test paths is avoided, thereby improving the test effect.
[0050] (2) The present invention reduces the number of test paths, avoids repeated testing of certain migrations, reduces the cost of testing, and improves the test effect. By considering the maximum number of contributions of nodes, the complexity of the test path can be reduced while ensuring the comprehensiveness of the test. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 A schematic diagram of a test path generation process based on the maximum contribution number of the present invention;
[0052] Figure 2 A schematic diagram of the loop search algorithm flow of the present invention;
[0053] Figure 3 The figure is a schematic diagram of the path generation algorithm flow of the present invention. DETAILED DESCRIPTION
[0054] In the first aspect, the present invention proposes a test path generation method based on the maximum contribution number. The test path generation method first finds the starting state of the state machine diagram, then uses a cyclic search algorithm to search the loop in the state machine diagram and calculates the number of times the state node appears in the loop, and finally traverses the loop according to the number of times the node appears to generate all test paths. The present invention can realize automatic generation of test paths for state machine diagrams with multiple loops, and the generated test paths can achieve maximum coverage of the state machine diagram and minimize the number of traversal loops.
[0055] The test path can be generated by traversing the graph. There are two more mature search and traversal algorithms for graphs, namely depth-first search (DFS) and breadth-first search (BFS). The depth-first search step is to traverse every possible branch in the path until it cannot go any deeper, and each node can only be visited once. The breadth-first search expands outward through the boundary between the found and unfound vertices, and searches in a hierarchical manner. The test path can be regarded as a directed path from the start node to the end node in a directed graph, so for test path generation, depth-first search is more suitable, while breadth-first traversal will generate incorrect test paths in some scenarios.
[0056] Test coverage criteria are the extent to which specified coverage items are executed using test tools. System models are usually highly complex and have many input items, and the number of test cases generated will be very large. However, in actual testing work, due to time and resource constraints, it is often impossible to execute every possible test case. Therefore, for effective testing, the concept of test coverage criteria is very important. Test coverage criteria provide a way to measure the extent to which a set of test cases execute a program, aiming to achieve an acceptable level of quality for the software through a defined standard strategy.
[0057] The traditional ZOT (Zero, One, Two) loop coverage criterion sets the number of loop executions to 0, 1, or 2. Under this coverage criterion, it is impossible to traverse a loop with multiple common nodes, resulting in the generated test cases being unable to cover all possibilities. To address this problem, the present invention defines a new coverage criterion, namely the maximum loop coverage criterion.
[0058] The test coverage standards of the present invention are defined as node coverage, migration edge coverage and maximum cycle coverage.
[0059] The node coverage indicates that all nodes in the state graph are executed at least once;
[0060] The transition edge coverage indicates that all transition edges in the state graph are executed at least once;
[0061] The maximum loop coverage means counting the number of times a state node appears in a common loop, counting the maximum number of times, and designing the number of times the loop is walked.
[0062] After defining the test coverage criteria, the test paths can be generated. Combined with the test coverage criteria, all test paths can be obtained by using the depth traversal algorithm.
[0063] There are three steps involved in the process of generating test paths using coverage criteria: first, traverse the state machine graph to find the start and end nodes in the graph; then, start from the initial node and traverse the state machine graph to search for all loops in the graph; finally, generate all test paths according to the coverage criteria.
[0064] Based on the description of the test path generation process above, the loop search algorithm and the test path generation algorithm are used to complete the specific test path generation:
[0065] Algorithm 1: Loop Finding Algorithm
[0066] Input: SysML state diagram
[0067] Output: All loops
[0068] (1) Obtain all vertexes and edges from the state machine graph
[0069] (2) Record the start and end nodes of the state machine graph from all nodes and edges:
[0070] For key in vertices
[0071] If key is not at the starting point of the edge, end = key
[0072] If key is not in all destinations, start = key
[0073] (3) Deeply traverse the initial node of the state machine graph and record the nodes and edges visited during the deep traversal
[0074] (4) Visit the neighboring nodes of the current node. If they have been visited, then this is a loop, return path
[0075] (5) Repeat (3) and (4) until the terminal node is reached.
[0076] After the loop search algorithm is used, all loops in the state machine graph can be obtained. According to all the loops found, the number of times each node appears in the loop is calculated, and the maximum number of times the node appears in the path is recorded. According to the calculated number of times, the state machine graph is traversed. If a loop is encountered, it is traversed that number of times to obtain all the test paths.
[0077] The following is an algorithm for automatically generating test paths:
[0078] Algorithm 2: Generate test path algorithm
[0079] Input: state machine diagram and all loops
[0080] Output: Test path
[0081] (1) Based on all loops, calculate the number of times each node appears in the loop.
[0082] (2) Record the maximum number of times a node appears in the loop
[0083] (3) Traverse the state machine diagram and start the deep traversal from the starting point of the state machine diagram
[0084] (4) Mark the current access node and the visited paths
[0085] (5) visited[current node] += 1, visit the current node and increase the number of visits to the current node by 1
[0086] (6) if current node = end of state machine diagram
[0087] Find a test path, return path
[0088] If the number of visits to the current node is less than or equal to the maximum count of the node
[0089] Repeat (3)-(6).
[0090] In a second aspect, the present invention further proposes a test path generation system based on the maximum contribution number, comprising: a loop search module and a test path automatic generation module; wherein:
[0091] The loop search module searches and records all loops through all nodes and edges in the state machine graph of the system, and outputs all recorded node information and loop information to the test path automatic generation module;
[0092] The test path automatic generation module calculates the number of times each node appears in the loop based on all the searched loops, and records the maximum number of times the node appears in the loop; it traverses the state machine diagram, and if a loop is encountered, it traverses the maximum number of times the node appears in the loop, thereby obtaining all test paths.
[0093] (1) The loop search module searches and records all loops through all nodes and edges in the system's state machine graph. Specifically:
[0094] S1-1 parses all nodes and edges from the state machine diagram;
[0095] S1-2 records the initial node and the terminal node of the state machine diagram from all nodes and edges;
[0096] S1-3 deeply traverses the initial node of the state machine graph, records the nodes and edges visited during the deep traversal, and records the node being visited during the process as the current node;
[0097] S1-4 visits the neighboring node of the current node. If the neighboring node has been visited, a loop is obtained and the information of the loop is recorded;
[0098] S1-5 returns to step S1-3 and iterates again until the terminal node is visited.
[0099] In the loop search module, the method of recording the initial node and the terminal node of the state machine graph from all nodes and edges is:
[0100] Iterate through all nodes:
[0101] If the current node does not belong to the starting point of any edge, it is considered to be a terminal node;
[0102] If the current node is not the end point of any edge, it is considered to be the initial node.
[0103] (2) In the test path automatic generation module, the state machine diagram is traversed. If a loop is encountered, the maximum number of times the node appears in the loop is traversed to obtain all the test paths, which are as follows:
[0104] S2-1 deeply traverses the state machine graph starting from the initial node;
[0105] S2-2 determines whether the depth traversal is finished based on the current access node. If the traversal is not finished, the current access node and the visited path are marked, and the number of visits to the current node is recorded; if the traversal is finished, the path generation is terminated;
[0106] S2-3 judges the current node:
[0107] If the current node is the terminal node in the state machine diagram, it is considered that a test path is found and the test path is recorded. After the recording is completed, return to S2-1 and traverse again;
[0108] If the number of visits to the current node is less than or equal to the maximum count of the node, return to S2-1 and traverse again.
[0109] In the test path automatic generation module, the depth traversal is judged based on the current access node to determine whether it is finished. Specifically:
[0110] If the current node has no unvisited adjacent nodes, and after backtracking to the previous node, the previous node has no unvisited adjacent nodes, and finally backtracking to the initial node and all the adjacent nodes of the initial node have been visited, the depth traversal ends.
[0111] The contents not described in detail in the specification of the present invention belong to the prior art known to the professional and technical personnel in this field.
Claims
1. A test path generation method based on maximum contribution times, characterized in that include: Search and record all loops through all nodes and edges in the system's state machine graph; According to all the loops searched, calculate the number of times each node appears in the loop, and record the maximum number of times a node appears in the loop; Traverse the state machine graph. If a loop is encountered, traverse the maximum number of times the node appears in the loop to obtain all test paths.
2. The test path generation method based on the maximum contribution number according to claim 1, characterized in that: Search and record all loops through all nodes and edges in the system's state machine graph, specifically: S1-1 parses all nodes and edges from the state machine diagram; S1-2 records the initial node and the terminal node of the state machine diagram from all nodes and edges; S1-3 deeply traverses the initial node of the state machine graph, records the nodes and edges visited during the deep traversal, and records the node being visited during the process as the current node; S1-4 visits the neighboring node of the current node. If the neighboring node has been visited, a loop is obtained and the information of the loop is recorded; S1-5 returns to step S1-3 and iterates again until the terminal node is visited.
3. The test path generation method based on the maximum contribution number according to claim 2, characterized in that: The method to record the initial node and the terminal node of the state machine graph from all nodes and edges is: Iterate through all nodes: If the current node does not belong to the starting point of any edge, it is considered to be a terminal node; If the current node is not the end point of any edge, it is considered to be the initial node.
4. The test path generation method based on maximum contribution times according to claim 1, characterized in that: Traverse the state machine graph. If a loop is encountered, traverse the maximum number of times the node appears in the loop to obtain all test paths, specifically: S2-1 deeply traverses the state machine graph starting from the initial node; S2-2 determines whether the depth traversal is completed based on the current access node. If the traversal is not completed, the current access node and the visited path are marked, and the number of visits to the current node is recorded; If the traversal is judged to be over, the path generation ends; S2-3 judges the current node: If the current node is the terminal node in the state machine diagram, it is considered that a test path is found and the test path is recorded; After recording is completed, return to S2-1 and traverse again; If the number of visits to the current node is less than or equal to the maximum count of the node, return to S2-1 and traverse again.
5. The test path generation method based on maximum contribution times according to claim 4, characterized in that: Determine whether the depth traversal is finished based on the current access node, specifically: If the current node has no unvisited adjacent nodes, and after backtracking to the previous node, the previous node has no unvisited adjacent nodes, and finally backtracking to the initial node and all the adjacent nodes of the initial node have been visited, the depth traversal ends.
6. A test path generation system based on maximum contribution times, characterized in that include: Loop search module and test path automatic generation module; wherein: The loop search module searches and records all loops through all nodes and edges in the state machine graph of the system, and outputs all recorded node information and loop information to the test path automatic generation module; The test path automatic generation module calculates the number of times each node appears in the loop based on all the loops searched, and records the maximum number of times a node appears in the loop; Traverse the state machine graph. If a loop is encountered, traverse the maximum number of times the node appears in the loop to obtain all test paths.
7. A test path generation system based on maximum contribution times according to claim 6, characterized in that: The loop search module searches and records all loops through all nodes and edges in the system's state machine graph, specifically: S1-1 parses all nodes and edges from the state machine diagram; S1-2 records the initial node and the terminal node of the state machine diagram from all nodes and edges; S1-3 deeply traverses the initial node of the state machine graph, records the nodes and edges visited during the deep traversal, and records the node being visited during the process as the current node; S1-4 visits the neighboring node of the current node. If the neighboring node has been visited, a loop is obtained and the information of the loop is recorded; S1-5 returns to step S1-3 and iterates again until the terminal node is visited.
8. A test path generation system based on maximum contribution times according to claim 7, characterized in that: In the loop search module, the method of recording the initial node and the terminal node of the state machine graph from all nodes and edges is: Iterate through all nodes: If the current node does not belong to the starting point of any edge, it is considered to be a terminal node; If the current node is not the end point of any edge, it is considered to be the initial node.
9. The test path generation system based on maximum contribution times according to claim 6, characterized in that: In the test path automatic generation module, the state machine diagram is traversed. If a loop is encountered, the maximum number of times the node appears in the loop is traversed to obtain all the test paths, specifically: S2-1 deeply traverses the state machine graph starting from the initial node; S2-2 determines whether the depth traversal is completed based on the current access node. If the traversal is not completed, the current access node and the visited path are marked, and the number of visits to the current node is recorded; If the traversal is judged to be over, the path generation ends; S2-3 judges the current node: If the current node is the terminal node in the state machine diagram, it is considered that a test path is found and the test path is recorded; After recording is completed, return to S2-1 and traverse again; If the number of visits to the current node is less than or equal to the maximum count of the node, return to S2-1 and traverse again.
10. A test path generation system based on maximum contribution times according to claim 9, characterized in that: In the test path automatic generation module, the depth traversal is judged based on the current access node to determine whether it is finished. Specifically: If the current node has no unvisited adjacent nodes, and after backtracking to the previous node, the previous node has no unvisited adjacent nodes, and finally backtracking to the initial node and all the adjacent nodes of the initial node have been visited, the depth traversal ends.