Using Unit Test Framework for Rules

Last Updated: 04/09/2018 Introduced in Version: 2.0
The rule engine has a unit test framework that allows you to write a suite of tests and execute them against your rule. This allows you to quickly see if your rule is returning the expected results. This functionality is very useful for verifying that changes made to existing rules have not broken the expected results of a rule.
 
Example
 
In this example we will create a simple rule that tests if two numbers are equal. Then we will build a suite of unit tests to evaluate the functionality of our rule.
 
Write a simple rule with two Int32 inputs (Name your inputs Number to Evaluate 1 and Number to Evaluate 2). This rule will evaluate if those two numbers are equal.
 
 
Click Debug Rule and under Unit Test select Add New. Enter Eval 9 and 9 for Test Name. Enter 9 for Number to Evaluate 1 and Number to Evaluate 2. Click Save and then close this window.
 
 
Add a new unit test and enter the following Test Name: Eval 6 and 6, Number to Evaluate 1: 6, and Number to Evaluate 2: 6. Click Save.
 
 
Add a new Unit Test and enter in the following information; Test Name: Eval 1 and 3, Number to Evaluate 1: 1, Number to Evaluate 2: 3. Click Save.
 
 
To run your new test suite, click Run All. This will run all three tests against your rule and evaluate the outcome of the rule compared to the expected outcome you specified in the test definition.
 
 
If you need to modify this rule in a way that breaks it (e.g. changing the Equals verb to the Greater Than verb), your unit tests will fail, alerting you that there is an issue. 

Additional Resources