Constraints are used to define which test cases will be included in the test output. Using constraints we can filter-out unwanted test cases.
A constraint is a logical expression in form PREMISE=>CONSEQUENCE, where a both PREMISE and CONSEQUENCE are logical statements in one of the following forms:
1) static statement (true or false), 2) relationship between a parameter and one of its choices, labels or a concrete value (more about labels in the next part of the tutorial), 3) relationship between two parameters, 4) a conjunction or disjunction of any number of the above statements.
Premise of a constraint works as a preliminary filter of test cases. If a premise evaluates to false, the constraint evaluates to true without the evaluation of the consequence.
If a premise evaluates to true, then the consequence is evaluated. In this case the result of the consequence evaluation is taken as a result of the constraint.
Constraints are evaluated one after another. If any constraint evaluates to false, the test case is removed from the test generation results.
A constraint in a model is a child of a method node, so it can be added from the method node context menu in the model page or in the method details page by clicking on the Add constraint button in the constraints viewer.
Let's add a constraint in our method and name it gender. Create a new constraint and change its type to implication. By default, it has a neutral form true=>true so it will always be satisfied. Go to the constraint's details page. We want to define a relationship between customer's gender and its given name. The constraint should ensure that whenever male choice is selected for Gender parameter, also one of choices that are leafs of male choice is selected for firstName parameter. Similarity for the female value of Gender. In other words, we want to filter out cases where the gender of Gender and firstName do not match. Use constraint editor to define the following constraint:
Click on the constraint's premise statement (the upper true). Now at the bottom of the details page you can edit the statement. Select OR from the combo box. Now, click two times Add statement button next to constraint editor.
You added two statements under the OR node, so now if one of them will be evaluated to true, the entire statement will evaluate to true as well (you know how boolean logic works, don't you). Change both statements to AND, and add two sub-statements for each. Now select one of the newly added statements (it should be a static "true" value).
In the combo box below the editor, select gender. You should see two other boxes appearing. The middle one defines the relation and the right one defines the compared element. We want the premise to have form gender=male[choice] (the word choice will distinguish the type of the right hand side element in case we defined a parameter or a label named male). Edit the other statements to get the constraint that we defined above. The consequence statement should be statically set to false.
Now we want to create a constraint for defining a relationship between documentType and documentSerialNumber parameters. Instead using complex logical expression like above, we can do it by three separate constraints.