/
Avoid Overuse of State Variables

Avoid Overuse of State Variables

State variables are an advanced modeling concept which enables use of a simple, explicit concept of “state” in a world of activity diagrams where state is only implicit in a control flow. It is intended to be used to keep track of “what has happened before” – similar to the “memory” concept in electronic calculators. Overuse of state variables, e.g., create and managing a lot of them in parallel makes models hard to follow. In particular, in large models it is easy to overlook proper setting of state variables in all flow branches and it gets difficult to find the root cause for unexpected test generation results. A good indicator for overuse of state variables is when you start getting increasingly confronted with variable initialization warnings in the Problems View of the Conformiq Modeling perspective.

Recommendation: Keep things simple and use as little state variables as possible. Avoid complex logic or maintaining multiple state variables in parallel.

To reduce your use of state variables restructure your control flows and manage state by reducing the amount of explicit and implicit merge nodes in your control flows.

Recommendation: Avoid “masking data” by assigning variables (including fields of variable data objects) to other (differently named) state variables and even worse converting data types. Instead (re)use action result or variable data object fields directly.

Another common use of state variables is to parameterize or influence selection of paths in a (very generic) sub diagram. This practice can easily backfire and create situations where it will never be possible to reach 100% coverage with default target settings, e.g., by calling a subactivity diagram with the state variable always and only set to one value and the sub activity having flows covering multiple settings. Note that expert users can remedy this situation by manually setting all the test targets related to sub activity diagram in Test Targets view of the Conformiq Test Generation perspective to “DON’T_CARE” (see “Review Testing Target Settings before Analyzing Your Model”).

Recommendation: Avoid use of state variables to select a subset of different flows in a sub activity diagram. Simplify you model for easing especially review with others: instead of using a state variable with a generic activity diagram, split this generic activity diagram into one activity diagram per case and eliminate state variable that is used.

 

 

Related content

Review Testing Target Settings before Analyzing Your Model
Review Testing Target Settings before Analyzing Your Model
More like this
Limit Use of Combinatorial Data to Avoid Test Case Explosion
Limit Use of Combinatorial Data to Avoid Test Case Explosion
More like this
Merge Nodes and Finalized Runs
Merge Nodes and Finalized Runs
More like this
Failing to Reach 100% Coverage
Failing to Reach 100% Coverage
More like this
Model Combinatorial Data with Combinatorial Action
Model Combinatorial Data with Combinatorial Action
More like this
Use Advanced Test Generation Concepts Only Once Functionality is Complete
Use Advanced Test Generation Concepts Only Once Functionality is Complete
More like this

Copyright © 2023 Conformiq and its subsidiaries. All rights reserved.