Skip to content

Home / Concepts / Constraints

Constraints

Constraints define rules about which parameter combinations are valid or invalid. They prevent the generation of impossible or meaningless test cases.

Why Constraints Matter

Not all parameter combinations make sense. For example:

  • Safari only runs on macOS
  • FAT file systems can't exceed 4 GB
  • Certain features require specific hardware

Without constraints, ProTest would generate test cases with these invalid combinations, wasting testing effort.

Constraint Syntax

ProTest uses PICT's native constraint language, which supports two forms:

Conditional Constraints

IF [OS] = "macOS" THEN [Browser] <> "Edge";
IF [FileSystem] = "FAT" THEN [Size] <= 4096;
IF [OS] = "Windows" THEN [Browser] = "Edge" ELSE [Browser] <> "Edge";

Unconditional Invariants

Unconditional invariants are constraints that always apply to every test case, with no IF/THEN condition. They are simply a predicate followed by a semicolon. Use them when a rule must hold regardless of any other parameter values.

[OS_1] <> [OS_2];
[Priority] >= 1;
[Timeout] <> 0;

In the first example, if your model has two OS parameters (e.g., source and target for a migration test), [OS_1] <> [OS_2] ensures they are always different — you never waste a test case migrating from Windows to Windows. The second ensures Priority is always at least 1. The third ensures Timeout is never zero. These rules apply unconditionally to every generated row.

Operators

Comparison Operators

Operator Meaning
= Equal
<> Not equal
> Greater than
>= Greater than or equal
< Less than
<= Less than or equal

Special Operators

Operator Syntax Meaning
LIKE [Param] LIKE "FAT*" Wildcard match (* = any chars, ? = one char)
IN [Param] IN { "A", "B", "C" } Value is in the set

Logical Operators

Operator Meaning
AND Both conditions must be true
OR At least one condition must be true
NOT Negates the condition
() Grouping for precedence

Parameter References

Parameters are referenced by name in square brackets: [ParameterName]

You can compare two parameters directly:

[MinValue] <= [MaxValue];

Full Grammar

Constraint ::=
    IF Predicate THEN Predicate [ELSE Predicate];
  | Predicate;

Predicate ::= Clause | Clause LogicalOperator Predicate

Clause ::= Term | ( Predicate ) | NOT Predicate

Term ::=
    [ParamName] Relation Value
  | [ParamName] LIKE PatternString
  | [ParamName] IN { ValueSet }
  | [ParamName] Relation [ParamName]

Relation ::= = | <> | > | >= | < | <=
LogicalOperator ::= AND | OR

Tips

  • End each constraint with a semicolon (;)
  • Use # for comments
  • String values must be quoted: "value"
  • Numeric values do not need quotes: 4096
  • The constraint editor in the UI provides IntelliSense for parameter names and values