You can test a declare expression individually, before testing it in the context of
the application that you are developing. Additionally, you can convert the test run to a Pega
unit test case.
Unit testing a declare expression involves specifying a test page for the rule to use,
providing sample data as the input, running the rule, and examining the results.
You can unit test Declare Expression rules for which all properties referenced in the
expression belong to a single Applies To class or to one class plus superclasses of that
class. For example, you cannot use this facility to test a computation that involves both a
Data-Account property and an Assign-Workbasket property.
The following considerations apply when unit testing a declare expression:
- Using data transforms – You can unit test a declare expression by using a data transform
to set property values or by manually entering values if all properties in the computation
are Single Value properties and they belong to a single
Applies To class.
- Testing expressions involving aggregate properties – If the expressions involve
aggregate properties, use this facility only with Page Group or
Page List properties with a small number of elements.
- Avoiding infinite loops – To avoid infinite loops caused by recursion, this facility
uses an internal limit of 999 computations, counting both iterations over List
and Group properties and expression evaluations. If this
limit is reached during a test execution, the evaluation ends with an error message.
Testing expressions involving special properties – Your expression can involve special
properties (standard properties with names starting with px or your properties marked as
special), Value List, or Value Group properties. You
cannot use manual inputs to change the value of a special property. Instead, you can
make changes to special properties by using a data transform.
- In the navigation pane of Dev Studio, click , and then select the declare expression that you want to test.
- Click .
- In the Test Page pane, select the context and test page to use
for the test:
- In the Data Context list, click the thread in which you want
to run the rule. If a test page exists for the thread, then it is listed and is used
for creating the test page.
- To discard all previous test results and start from a blank test page, click
- To apply a data transform to the values on the test page, click the data transform
link, and then select the data transform you want to use.
- In the bottom area of the window, enter values to use for the properties in the
declarative network. For each property value, click the property, enter a value for the
property in the Property field, and then click
Update. Each time an input property is changed, the expression is
- If the unit test of the Declare Expression rule requires creating an input that is part
of an embedded Page List or Page Group property, create
a new page by performing the following actions:
- Select the Add new page check box.
- For a Page Group, enter an identifier as a subscript value.
For a Page List, the system appends the new page after existing
- From the Class list, select the class of the page.
- Click Update.
You can also add inputs to Value List or Value Group
- To convert the test run into a Pega unit test case, click Convert to
Test. For more information, see Creating unit test cases for rules.