Rule Debugging and Unit Tests
  • 28 Jul 2022
  • 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. It is common practice to create a Unit Test that will render both a true and false scenario for accuracy.

Prerequisite
This article covers using the Debugger to determine the output for a Rule, along with an understanding of how to create a unit test. Please visit the following articles for more information:

Example

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

  1. Select the Debug button from the top Action Bar in the Rule Designer to test the logic.
  2. 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. 
  3. Once the inputs have been added, select START DEBUGGING. 
  4. The information that is entered should be expected to either evaluate as true or false. The result will be shown in the Debugger.
  5. Once finished, select the Save As Data Sample button to create new SAMPLE DATA. 
  6. 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

  1. 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
  2. To create a Unit Test, provide a Test Name and sample data to the [UNIT TEST DATA] section.
  3. The EDIT UNIT TEST RULE button can be used to configure additional conditions, specifically the true or false evaluation of the Rule.
    This Rule is always rendered by default but does not typically need to be modified. For more information, please visit our advanced article on Unit Testing.
  4. When either SAMPLE DATA tests or UNIT TESTS are available, select the play icon to automatically run the test with the pre-defined data, or use the Run All button to initiate all tests.

Was this article helpful?