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 Pega unit 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, Pega unit 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.
- Click and select the when rule that you want to open.
- Click Actions > Run.
- In the Thread list in the Run context pane, select the thread in which you want to run the rule.
-
Specify initial setup values for the clipboard.
-
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.
-
- 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.
-
In the Page list, select one of the following options:
- Optional: On the main test page, enter the values for parameters to pass to the rule.
- Click Run to display the result that is returned by the test.
- Optional:
Convert this test into a Pega unit test case.
- Click Convert to test. A new tab is displayed in the main Dev Studio window.
- Configure the Pega unit test case. For more information, see Configuring Pega unit test cases.
- Optional: Click Clipboard to open the Clipboard and review the pages that are generated by the unit test.
- Optional: If the rule has errors, click Trace to debug the rule with the Tracer tool.