Unit testing a when rule

You can test a when rule individually before testing it in the context of the application that you are developing. To test a when rule, use the Run Rule feature. Optionally, you can convert the run into a PegaUnit test case to validate application data by comparing expected property values to the actual values that are returned by the test. In a continuous delivery environment, PegaUnit testing provides you with feedback on the quality of your applications, so that you can quickly identify issues and correct them.

By default, when you run the when rule, the result assertion uses the input value that you enter and the result that is returned. The assertion is generated when you convert this test to a test case.

  1. Click Records > Decision > When and select the when rule that you want to open.
  2. Click Actions > Run.
  3. In the Thread list in the Run context pane, select the thread in which you want to run the rule.
  4. Specify initial setup values for the clipboard.
    1. In the Page list, select one of the following options:
      • Copy existing page – Select to copy values on an existing clipboard page in the selected thread to RunRecordPrimaryPage, the main test page. Then, in the Page to copy list, select the page whose values you want to copy.

      • Empty test page – Select if you do not want to prepopulate RunRecordPrimaryPage with values from an existing page.

    2. Optional: Select the Apply data transform check box and select a data transform to apply to the values on the page.
      Note: The system always runs the rule instance on the RunRecordPrimaryPage, regardless of the page that you select from this list. If you convert this rule run to a test case, and the RunRecordPrimaryPage requires initial values, configure the clipboard so that it populates the page with initial values. For more information, see Setting up your test environment.
  5. Optional: On the main test page, enter the values for parameters to pass to the rule.
  6. Click Run to display the result that is returned by the test.
  7. Optional: Convert this test into a PegaUnit test case.
    1. Click Convert to test. A new tab is displayed in the main Designer Studio window.
    2. Configure the PegaUnit test case. For more information, see Configuring PegaUnit test cases.
  8. Optional: Click Clipboard to open the Clipboard and review the pages that are generated by the unit test.
  9. Optional: If the rule has errors, click Trace to debug the rule with the Tracer tool.