- 28 Jul 2022
- 2 Minutes to read
Rule Debugging and Unit Tests
- Updated on 28 Jul 2022
- 2 Minutes to read
Rules exist in Decisions to evaluate incoming data against certain conditions, typically in order to reach a true or false outcome as to whether or not the data meets the conditions. Rule logic can be tested using the Debugger built into the Rule Designer. Test information can be entered into the debugger for a one-time evaluation against the Rule, or it can be saved as a Unit Test. It is common practice to create a Unit Test that will render both a true and false scenario for accuracy.
This example uses a Rule that checks to see if the country is the US, and either the state is in a list, or the age is between 20 and 40. The Rule will receive values for each piece of input data; Country [String], State [String], and Age [Int32]. This data is then evaluated against the conditions. The Debugger provides a place to enter sample data that will correspond with the expected input data types. This example will be separated into two parts, one on how to create Sample Data and the other for creating Unit Tests for Rules.
Creating Sample Data
- Select the Debug button from the top Action Bar in the Rule Designer to test the logic.
- The first available function in the Debugger is to enter sample data in the INPUT DATA section. Here we can add the needed inputs for the Rule.
- Once the inputs have been added, select START DEBUGGING.
- The information that is entered should be expected to either evaluate as true or false. The result will be shown in the Debugger.
- Once finished, select the Save As Data Sample button to create new SAMPLE DATA.
- Select the Create Sample Type checkbox to create a new type or deselect and choose an existing type. Once finished, Save. New Sample data will appear under the SAMPLE DATA header on the left.
Creating a Unit Test
- The Save As Unit Test button or the Add New button under the INPUT DATA section can be used to create new Unit Tests. Typically Unit Tests are configured to contain sample data that will exercise both the true and false evaluation of the Rule.