Skip to main content
LinkedIn
Copied!

Table of Contents

Unit testing a declare expression

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.

  1. In the navigation pane of Dev Studio, click Records Decision Declare Expression , and then select the declare expression that you want to test.

  2. Click Actions Run .

  3. In the Test Page pane, select the context and test page to use for the test:

    1. 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.

    2. To discard all previous test results and start from a blank test page, click Reset Page.

    3. 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.

  4. 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 automatically reevaluated.

  5. 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:

    1. Select the Add new page check box.

    2. For a Page Group, enter an identifier as a subscript value.

      For a Page List, the system appends the new page after existing pages.
    3. From the Class list, select the class of the page.

    4. Click Update.

    You can also add inputs to Value List or Value Group properties.
  6. 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.

Did you find this content helpful?

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Ready to crush complexity?

Experience the benefits of Pega Community when you log in.

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us