Rule Debugging and Unit Tests
  • 07 May 2021
  • 2 Minutes to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Rule Debugging and Unit Tests

  • Dark
    Light

Article summary

Overview

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 for running again later on. It is common practice to create a Unit Test that will render both a true and false scenario for accuracy purposes.

Example

In this example, a simple Rule will be created that tests to see if two numbers are equal. After the Rule is built, a suite of unit tests will be created to evaluate the functionality of the Rule.

  1. In a Designer Folder, click CREATE RULE on the GLOBAL ACTION BAR at the bottom of the screen.
  2. Click CREATE for the Default template under Statement Rule, name the Rule, and click CREATE.
  3. In the Rule Designer, click SETUP INPUT DATA at the top. When the Data Definitions window appears, create two data inputs (First Number, Second Number) as an Int32 [Number] type.
    2019-12-05_16h27_22.gif
  4. Configure the If statement for this Rule so that First Number equals Second Number. Expand the Select Data Element drop-down list and select First Number, then click NEXT. On the Pick Verb window, select Equals under the Number Rules section then click NEXT. Under the Inputs section of the next window, expand the Constant drop-down list for value2 and select Select From Flow. Select Second Number from the list and click DONE.
    2019-12-05_16h33_15.gif



Debug

  1. Select the Debug button at the top of the Rule Designer.
  2. In the Rule Example Data section, locate the area for Unit Tests and select the Add New button. Configure the Test Name to be "Evaluate 9 and 9" and leave the Test Result Evaluation Rule as is. Under the Input Data section, enter "9" for both First and Second Number then click Save.
    For more information editing the Test Result Evaluation Rule, please visit our Unit Testing (Advanced) document.


    2019-12-05_16h45_28.gif
  3. Follow the same steps detailed above to create a second unit test for the Rule. Configure the Test Name to be "Evaluate 6 and 6", with both First and Second Number being 6. Create a third unit test for the Rule and configure the Test Name to be "Evaluate 1 and 3", with First Number being 1 and Second Number being 3.
    2019-12-05_16h52_13.gif
  4. With the list of Unit Tests for this Rule, select the Run All button in the Unit Tests section. This action will run all three tests against the created Rule and evaluate the outcome of the Rule to the expected outcome that was specified in the test definition. A green checkmark means that the Rule ran successfully. To take a look at individual results, click the triangle to the right of the Test Name to take a look at the evaluation.
    2019-12-05_16h56_11.gif




Was this article helpful?