pega4engineers
Unit Testing in PEGA
Unit testing supports the continuous delivery of applications by enabling quality testing of individual rules and cases. An incorrect rule configuration in an application can cause delays in case processing. When an error occurs, end users may need to reassign work, or a case may require repair by an administrator.
When you create a PegaUnit test case for a flow or case type, you run the flow or case type and enter data for assignments and decisions. The system records the data that you enter in a data transform, which is created after you save the test form. You can start recording at any time.
Let's create a unit test case and see how it works.
1. Create a new ruleset to store the test cases.


2. Include the ruleset in application ruleset stack to access and store the test cases.

3. Open the case type and from the toolbar, click Action > Record test case. The system starts running the case type.

4. Click Create test case in the bottom right corner of the browser to start recording the test case and create a test case in a new tab.

5. Enter all the data as you run the case type.
6. The test case will contain all the information that have entered when you create the test case.

7. Click Add properties to check if all the desired properties are present.

8. Save the rule. While saving rule you may not see the ruleset version in the wizard.
This happens because of the “use the ruleset to store test cases” checkbox left unchecked while creating the ruleset.
9. Enable the checkbox from the security tab of the ruleset rule and save it.

10. Go back to the test case and save it. Now you can see the ruleset version in the save wizard.

11. This unit test case checks if the existing case has all the values similar to the ones created on the test case. If the values are similar the test case passes. Else it fails.
12. To check that, we have declared a few properties with default values in pyDefault data transform.

13. Open the test case and from the toolbar, click Action > Run.

14. Since all the values in the data transform are similar to the ones in the test case, It will get passed.


15. Let's change any value in the pyDefault data transform and check if the test case still passes. Here the contact number property is changed.

16. Run the test case.
17. Since the contact numbers don't match, the test case fails.


Voilà !! Test case works as expected.
Note: It is not mandatory that the property values should be set in pyDefault. You can set the values in any data transform all call it in the flow.
Some properties, like .pyID, are not processed when a PegaUnit test case is run. These properties vary for every test run. The pxDataCapturePropertyIgnores data transform displays the properties that PegaUnit tests do not process.

You can also add any new case properties or py properties that are to be ignored in the pyDataCapturePropertyIgnores called in step 16 of the previous data transform.
Happy learning! 🤠