A method of converting an activity graph to a state graph and generating test cases

By converting activity diagrams into state diagrams and generating test cases, the problem that activity diagrams cannot directly generate test cases is solved, enabling the assessment of test coverage and the assurance of quality, thereby improving the effectiveness and efficiency of software testing.

CN115470103BActive Publication Date: 2026-07-21BEIJING RESEARCH INSTITUTE OF MECHANICAL & ELECTRICAL TECHNOLOGY CO LTD CAM
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING RESEARCH INSTITUTE OF MECHANICAL & ELECTRICAL TECHNOLOGY CO LTD CAM
Filing Date
2022-08-16
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In existing technologies, activity graphs cannot directly generate test cases, resulting in the inability to assess test coverage, the inability to guarantee test quality, and low testing efficiency and high costs.

Method used

By converting activity diagrams into state diagrams and ensuring no paths are omitted during the conversion process, test cases are generated, and the directional nature of state diagrams is used to automatically generate test paths.

Benefits of technology

It enables the assessment of test coverage and the assurance of quality, improves the effectiveness and efficiency of software testing, and meets the sufficiency and coverage requirements of missile-borne interactive software testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115470103B_ABST
    Figure CN115470103B_ABST
Patent Text Reader

Abstract

This paper presents a method of converting activity graph to state graph and generating test cases, through which the activity graph is converted to state graph, and the multi-scene replication method is adopted for concurrent nodes in the activity graph, so as to ensure that the path of the converted state graph is not missed. Testers can use the coverage criteria of the state graph to guide the automatic generation of test cases after converting the activity graph to the state graph by this method. This method can meet the sufficiency coverage requirements of missile-borne interactive software testing needs, and improve the effectiveness and efficiency of software testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of software testing technology, specifically relating to a method for converting activity diagrams into state diagrams and generating test cases. Background Technology

[0002] Interactive software onboard aircraft presents complex interaction scenarios. Testers typically use activity diagrams to model software requirements for testing. However, since activity diagrams are not directed graphs, test cases cannot be directly generated. Testers usually need to manually derive test paths from the model to generate test cases. This approach leads to two main problems: first, test coverage cannot be assessed, and test quality cannot be guaranteed; second, testing efficiency is low, and testing costs are high. Summary of the Invention

[0003] The technical problem solved by this invention is to propose a method for converting activity diagrams into state diagrams and generating test cases, ensuring that no paths are omitted in the converted state diagrams, thereby improving the effectiveness and efficiency of software testing.

[0004] This invention provides a method for converting an activity diagram to a state diagram and generating test cases, comprising the following steps:

[0005] I. Define Activity Diagrams and State Diagrams

[0006] An activity diagram describes the activities performed by a group of objects in the process of collaborating to complete a task, as well as the order of those activities, showing the control flow from one activity to another.

[0007] Mathematical representation of activity diagrams: An activity diagram is a quadruple. ,in:

[0008] 1) Where AN is the set of active nodes and ON is the set of object nodes. Ch is the set of branch nodes, Me is the set of merge nodes, Fo is the set of fork nodes, and Jo is the set of merge nodes.

[0009] 2) R represents the relationship between nodes;

[0010] 3) I is the set of initial nodes;

[0011] 4) F is the set of terminating nodes;

[0012] A state diagram describes the sequence of states an object goes through in response to events during its lifecycle, as well as the stimuli or events that trigger the response; its components include states, transitions, and events.

[0013] Mathematical representation of state diagrams: Let Represent a state transition diagram, where It is the set of initial states. It is a set of terminating states. It is a set of state transitions. It is an event that triggers a transition between two adjacent states;

[0014] II. The process of converting an activity diagram to a state diagram:

[0015] 1) Convert the activities of the object under test in the activity diagram into states in the state diagram;

[0016] 2) Convert the action flow representing the execution order between activities in the activity diagram into transitions in the state diagram;

[0017] 3) Convert the conditions that need to be judged in the action flow to be executed in the activity diagram into the event conditions that the transitions in the state diagram must satisfy;

[0018] 4) Ignore outgoing edges that originate from the tested object and reach other swimlane objects;

[0019] 5) For the incoming edge of a specific activity from another swimlane object, convert the input activity associated with the incoming edge and its object into a trigger event on the state transition.

[0020] 6) When there is no input from other objects during the transition, and the state transition is only related to the change of a certain value or the change of the system state, this change can be converted into a change event that triggers the state transition.

[0021] 7) When transitioning, if there is no input from other objects and the execution of an activity is only related to its own state and time, then the change in time can be used as the time event that triggers the state transition.

[0022] 8) In the activity diagram, merge multiple activities under the tested object that are executed sequentially and have no intermediate judgment conditions into a single state;

[0023] 9) In the activity diagram, the branch judgment under the tested object is omitted, and the conditional execution flow from the current activity to other activities represented by the branch is transformed into a conditional transition from the state represented by the current activity to the state represented by other activities.

[0024] 10) For a branch node in the activity graph that represents the start of concurrency, if there is an outgoing edge to another object in the outgoing edge of the branch node, then remove that outgoing edge directly; for the remaining N outgoing edges, copy the previously transformed state graph N times, with each state graph corresponding to one outgoing edge, and then continue to perform the transformation from activity graph to state graph along the path represented by each outgoing edge; if a branch node representing the start of concurrency is encountered again, then according to the above strategy, multiple state graphs are obtained by copying.

[0025] Furthermore, the conversion process from activity diagram to state diagram specifically includes,

[0026] First, input the activity graph to store the activity graph structure of each node and edge, and then perform the following steps:

[0027] The first step is to initialize a state graph object z.

[0028] The second step is to find the starting node and create the starting state node of the state graph.

[0029] Determine if the current node is the starting node and does not belong to the system under test. Traverse all subsequent nodes of the starting node. If a subsequent node does not belong to the system under test, delete the node and related edges. Continue until a node of the system under test is encountered, then determine if the current node is the starting node and belongs to the system under test.

[0030] The third step is to find the termination node and create a termination state node in the state graph.

[0031] Determine if the current node is a termination node and does not belong to the system under test. Traverse all nodes before the termination node. If a node before the termination node does not belong to the system under test, delete the node and related edges until a node of the system under test is encountered.

[0032] The fourth step is to find ordinary nodes and create ordinary state nodes in the state graph.

[0033] Fifth step, add transfer and event condition information.

[0034] Convert the edges connected to the nodes into state transitions, convert the activities connected to the edges into states in the state graph, convert the conditions on the edges into guard conditions on the state transitions, and add them to the various state graph objects that have been obtained.

[0035] Step 6: Repeat steps 2 through 5 in a loop to traverse all nodes in the activity graph.

[0036] Furthermore, the fourth step specifically includes the following steps:

[0037] 1) Determine whether the current node is a normal active node and does not belong to the system under test, and mark the node and related edges as deleted;

[0038] 2) Determine if the current node belongs to the system under test and is a concurrent node. First, start traversing from each subsequent node until the concurrent end node is encountered. Generate k paths from the concurrent start node to the concurrent end node. Then, copy the state graph object z k times and add the k paths to the k state graph objects respectively.

[0039] 3) If the current node is a normal node belonging to the system under test, and its predecessor node is a node of another object and its successor is not a judgment node, create a state node in the state diagram, record the active node corresponding to the state node, and add the state node to each state diagram object.

[0040] 4) If the current node is a normal node belonging to the system under test, and its predecessor node in the system under test exists and is also a normal node, and the subsequent node is not the node to be judged, then merge the node content into the state corresponding to the predecessor node of the node in each state diagram object, and record the active node.

[0041] 5) Determine if the current node is a normal node belonging to the system under test, and if its predecessor node in the system under test exists and is also a normal node. When judging the node in the subsequent process, merge the node content into the state corresponding to the predecessor node of the node in each state diagram object, record the active node, and determine if there are any nodes belonging to other objects in the predecessor nodes of the node. If so, use the nodes from other objects as the triggering events for the conditions in the next judgment.

[0042] This algorithm automatically converts activity diagrams to state diagrams. For concurrent nodes in the activity diagram, a multi-scenario replication method ensures no path is missed in the converted state diagram, and no related objects, nodes, timing information, or control information is lost. Furthermore, after converting the activity diagram to a state diagram, since the state diagram is a directed graph, testers can automatically generate various state transition sequences reflecting the correct behavior of the software system based on existing coverage criteria and test case claims, thus forming test cases. This approach satisfies the sufficiency and coverage requirements of interactive software testing, while improving the effectiveness and efficiency of software testing. Attached Figure Description

[0043] Figure 1. Algorithm flowchart;

[0044] Figure 2. Activity diagram for matching and positioning;

[0045] Figure 3 The activity graph is transformed into one of the state graphs for matching and positioning;

[0046] Figure 4 shows the second state diagram of the activity diagram transitioning to matching and positioning. Detailed Implementation

[0047] The present invention will be further described in detail below with reference to the accompanying drawings. The technical solution of the present invention is as follows:

[0048] I. Definition of Activity Diagram:

[0049] Activity diagrams are a common tool for modeling the dynamic behavior of a system. They describe the activities performed by a group of objects as they collaborate to complete a task, and the sequence of these activities, showing the control flow from one activity to another.

[0050] Mathematical representation: An activity diagram is a quadruple. ,in:

[0051] 1) Where AN is the set of active nodes and ON is the set of object nodes. Ch is the set of branch nodes, Me is the set of merge nodes, Fo is the set of fork nodes, and Jo is the set of merge nodes.

[0052] 2) R represents the relationship between nodes;

[0053] 3) I is the set of initial nodes;

[0054] 4) F is the set of terminating nodes.

[0055] II. Definition of State Diagram:

[0056] A state diagram describes the sequence of states an object goes through in response to events during its lifecycle, as well as the stimuli or events that trigger those responses. Its components include states, transitions, and events.

[0057] Mathematical expression: Let Represent a state transition diagram, where It is the set of initial states. It is a set of terminating states. It is a set of state transitions. It is an event that triggers a transition between two adjacent states.

[0058] III. Rules for converting activity diagrams to state diagrams:

[0059] 1) Convert the activities of the object under test in the activity diagram into states in the state diagram;

[0060] 2) Convert the action flow representing the execution order between activities in the activity diagram into transitions in the state diagram;

[0061] 3) Convert the conditions that need to be judged in the action flow to be executed in the activity diagram into the event conditions that the transitions in the state diagram must satisfy;

[0062] 4) Ignore outgoing edges that originate from the tested object and reach other swimlane objects;

[0063] 5) For the incoming edge of a specific activity from another swimlane object, convert the input activity associated with the incoming edge and its object into a trigger event on the state transition.

[0064] 6) When there is no input from other objects during the transition, and the state transition is only related to the change of a certain value or the change of the system state, this change can be converted into a change event that triggers the state transition.

[0065] 7) When transitioning, if there is no input from other objects and the execution of an activity is only related to its own state and time, such as making a judgment every few seconds, then the change in time can be used as the time event that triggers the state transition.

[0066] 8) In the activity diagram, designate a certain swimlane as the test object, and merge multiple activities that are executed sequentially and have no intermediate judgment conditions into the same state;

[0067] 9) In the activity diagram, a swimlane is designated as the object to be tested. The branch judgment represented by the diamond is omitted. The conditional execution flow from the current activity to other activities represented by the branch is transformed into a conditional transition from the state represented by the current activity to the state represented by other activities.

[0068] 10) For a branch node in the activity graph that represents the start of concurrency, if any of its outgoing edges lead to other objects, remove that outgoing edge. For the remaining N outgoing edges, copy the previously transformed state graph N times, with each state graph corresponding to one outgoing edge. Then continue the transformation from activity graph to state graph along the path represented by each outgoing edge. If more branch nodes representing the start of concurrency are encountered subsequently, multiple state graphs are obtained by copying them according to the above strategy.

[0069] IV. The specific conversion algorithm is as follows:

[0070] Input: Activity graph (the structure of the activity graph storing each node and edge)

[0071] like Figure 1 As shown, the steps of the conversion algorithm are as follows:

[0072] Step 1: Initialize a state graph object z

[0073] Step 2: Find the starting node and create the starting state node of the state graph. The method is as follows: determine whether the current node is the starting node and does not belong to the system under test, traverse all subsequent nodes of the starting node, if a subsequent node does not belong to the system under test, delete the node and related edges, until a node of the system under test is encountered, and then determine whether the current node is the starting node and belongs to the system under test.

[0074] Step 3: Find the termination node and create a termination state node in the state graph. The method is as follows: determine whether the current node is a termination node and does not belong to the system under test, traverse all nodes preceding the termination node, and if a preceding node does not belong to the system under test, delete the node and related edges until a node of the system under test is encountered;

[0075] Step 4: Find ordinary nodes and create ordinary state nodes in the state graph. The method is as follows:

[0076] 1) Determine whether the current node is a normal active node and does not belong to the system under test, and mark the node and related edges as deleted;

[0077] 2) Determine if the current node belongs to the system under test and is a concurrent node. First, start traversing from each subsequent node until the concurrent end node is encountered. Generate k paths from the concurrent start node to the concurrent end node. Then, copy the state graph object z k times and add the k paths to the k state graph objects respectively.

[0078] 3) If the current node is a normal node belonging to the system under test, and its predecessor node is a node of another object and its successor is not a judgment node, create a state node in the state diagram, record the active node corresponding to the state node, and add the state node to each state diagram object.

[0079] 4) If the current node is a normal node belonging to the system under test, and its predecessor node in the system under test exists and is also a normal node, and the subsequent node is not the node to be judged, then merge the node content into the state corresponding to the predecessor node of the node in each state diagram object, and record the active node.

[0080] 5) Determine if the current node is a normal node belonging to the system under test, and if its predecessor node in the system under test exists and is also a normal node, and if the node is to be judged later, merge the node content into the state corresponding to the predecessor node of each state diagram object, record the active node, and determine if there is a node belonging to other objects in the predecessor node of the node. If so, use the node from other objects as the trigger event for the conditions in the next judgment.

[0081] The fifth step is to add transition and event condition information. This involves converting edges connected to the decision nodes into state transitions, converting activities connected to the edges into states in the state graph, and converting the conditions on the edges into guard conditions on the state transitions. These are then added to the various state graph objects already obtained.

[0082] Step 6: Repeat steps 2 through 5 to traverse all nodes in the activity graph.

[0083] Taking matching and location software as an example, Figure 2The activity diagram is for matching and positioning. Figures 3 and 4 are the state diagrams of the activity diagram being transformed into matching and positioning.

[0084] The above-described specific embodiments are limited to explaining and illustrating the technical solutions of the present invention, but do not constitute a limitation on the scope of protection of the claims. Those skilled in the art should understand that any new technical solutions obtained by making simple modifications or substitutions based on the technical solutions of the present invention fall within the scope of protection of the present invention.

Claims

1. A method for converting activity diagrams to state diagrams and generating test cases, characterized in that, Includes the following steps: I. Define Activity Diagrams and State Diagrams An activity diagram describes the activities performed by a group of objects in the process of collaborating to complete a task, as well as the order of those activities, showing the control flow from one activity to another. Mathematical representation of activity diagrams: An activity diagram is a quadruple. ,in: 1) Where AN is the set of active nodes and ON is the set of object nodes. Ch is the set of branch nodes, Me is the set of merge nodes, Fo is the set of fork nodes, and Jo is the set of merge nodes. 2) R represents the relationship between nodes; 3) I is the set of initial nodes; 4) F is the set of terminating nodes; A state diagram describes the sequence of states an object goes through in response to events during its lifecycle, as well as the stimuli or events that trigger the response; its components include states, transitions, and events. Mathematical representation of state diagrams: Let Represent a state transition diagram, where It is the set of initial states. It is a set of terminating states. It is a set of state transitions. It is an event that triggers a transition between two adjacent states; II. The process of converting an activity diagram to a state diagram: 1) Convert the activities of the object under test in the activity diagram into states in the state diagram; 2) Convert the action flow representing the execution order between activities in the activity diagram into transitions in the state diagram; 3) Convert the conditions that need to be judged in the action flow to be executed in the activity diagram into the event conditions that the transitions in the state diagram must satisfy; 4) Ignore outgoing edges that originate from the tested object and reach other swimlane objects; 5) For the incoming edge of a specific activity from another swimlane object, convert the input activity associated with the incoming edge and its object into a trigger event on the state transition. 6) When there is no input from other objects during the transition, and the state transition is only related to the change of a certain value or the change of the system state, this change can be converted into a change event that triggers the state transition. 7) When transitioning, if there is no input from other objects and the execution of an activity is only related to its own state and time, then the change in time can be used as the time event that triggers the state transition. 8) In the activity diagram, designate a certain swimlane as the test object, and merge multiple activities that are executed sequentially and have no intermediate judgment conditions into the same state; 9) In the activity diagram, designate a certain swimlane as the object to be tested, omit the branch judgment, and convert the conditional execution flow from the current activity to other activities represented by the branch into a conditional transition from the state represented by the current activity to the state represented by other activities. 10) For a branch node in the activity graph that represents the start of concurrency, if any outgoing edge of the branch node leads to another object, remove that outgoing edge directly. For the remaining N outgoing edges, copy the previously transformed state graph N times, with each state graph corresponding to one outgoing edge, and then continue to perform the transformation from activity graph to state graph along the path represented by each outgoing edge. If a branch node representing the start of concurrency is encountered again, multiple state graphs are obtained by copying them in the same way as described above. 11) After converting the activity diagram into a state diagram, since the state diagram is a directed graph, testers can automatically generate various state transition sequences that reflect the correct behavior of the software system based on existing coverage criteria and test case claim algorithms, and form test cases.

2. The method for converting an activity diagram to a state diagram and generating test cases according to claim 1, characterized in that, The process of transforming an activity diagram into a state diagram specifically includes, First, input the activity graph to store the activity graph structure of each node and edge, and then perform the following steps: The first step is to initialize a state graph object z. The second step is to find the starting node and create the starting state node of the state graph. Determine if the current node is the starting node and does not belong to the system under test. Traverse all subsequent nodes of the starting node. If a subsequent node does not belong to the system under test, delete the node and related edges. Continue until a node of the system under test is encountered, then determine if the current node is the starting node and belongs to the system under test. The third step is to find the termination node and create a termination state node in the state graph. Determine if the current node is a termination node and does not belong to the system under test. Traverse all nodes before the termination node. If a node before the termination node does not belong to the system under test, delete the node and related edges until a node of the system under test is encountered. The fourth step is to find ordinary nodes and create ordinary state nodes in the state graph. Fifth step, add transfer and event condition information. Convert the edges connected to the nodes into state transitions, convert the activities connected to the edges into states in the state graph, convert the conditions on the edges into guard conditions on the state transitions, and add them to the various state graph objects that have been obtained. Step 6: Repeat steps 2 through 5 in a loop to traverse all nodes in the activity graph.

3. The method for converting an activity diagram to a state diagram and generating test cases according to claim 2, characterized in that, The fourth step specifically includes the following steps: 1) Determine whether the current node is a normal active node and does not belong to the system under test, and mark the node and related edges as deleted; 2) Determine if the current node belongs to the system under test and is a concurrent node. First, start traversing from each subsequent node until the concurrent end node is encountered. Generate k paths from the concurrent start node to the concurrent end node. Then, copy the state graph object z k times and add the k paths to the k state graph objects respectively. 3) If the current node is a normal node belonging to the system under test, and its predecessor node is a node of another object and its successor is not a judgment node, create a state node in the state diagram, record the active node corresponding to the state node, and add the state node to each state diagram object. 4) If the current node is a normal node belonging to the system under test, and its predecessor node in the system under test exists and is also a normal node, and the subsequent node is not the node to be judged, then merge the node content into the state corresponding to the predecessor node of the node in each state diagram object, and record the active node. 5) Determine if the current node is a normal node belonging to the system under test, and if its predecessor node in the system under test exists and is also a normal node. When judging the node in the subsequent process, merge the node content into the state corresponding to the predecessor node of the node in each state diagram object, record the active node, and determine if there are any nodes belonging to other objects in the predecessor nodes of the node. If so, use the nodes from other objects as the triggering events for the conditions in the next judgment.