While the analyze phase helps to ensure the logical integrity of the rules, the Test phase helps to ensure that the rules give correct business results.

First, define a test case for each one of the rules by defining some input values and expected results. Corticon Studio enables you to define our expected results, and then highlights any differences between the actual test results and the expected results. The following table defines one test case for each rule in the Rulesheet.

For Test Case 2, we expect Rule 2 to override Rule 1. Even though the cargo weight is less than 20,000, which also satisfies the condition of Rule 1, the cargo volume is greater than 30, so Rule 2 overrides Rule 1 and is triggered.

Create a Ruletest file

To begin testing, create a Ruletest file:

  1. Select File > New > Ruletest.
  2. In the Create New Ruletest wizard, check that the parent folder is Tutorial, and then enter Cargo as the file name. Click Next.
  3. Ensure that Cargo.ers is selected as the Test Subject, and then click Finish.

The Ruletest file opens in Corticon Studio on a new testsheet, untitled_1, as shown.



As you can see, your new Ruletest is associated with the appropriate Rulesheet, ensuring that your Ruletest scenario tests the right rules.

Set up test cases

  1. Drag the Cargo entity from the Vocabulary and drop it anywhere in the Input and the Expected panes of the Ruletest.

    Note: Cargo [1] on the Input and Expected panes represents a single instance or example of the Cargo entity. Changes you make to any Corticon Studio file causes an asterisk character to appear in the file’s tab as a reminder to save the file.
  2. Remove unneeded attributes by selecting them and pressing the Delete key. In this case, remove manifestNumber from both Input and Expected as it is not needed to test these rules.
  3. Add test data for Test Case 1 to the TestSheet, as in this table.

  4. Double-click the terms weight and volume in the Input column to enter their values.
  5. Do the same in the Expected column by entering the container value.

  6. Enter the remaining test data based on the test cases in the table.

  7. Duplicate the first test case by selecting Cargo [1], copying it, and then pasting it in the Input pane. Then, modify the input values based on the test cases. Repeat these steps for the Expected pane. Press Tab to advance through the entry boxes. Specify values for container in the Expected pane—you can select these values from the container drop-down list. Your Ruletest should now look like this:

    The Input column expects all its container values to be null. If you click container and enter nothing, you still set a value, as illustrated for Cargo [1]:



  8. To correct it, click container [] and then right-click to choose Set to Null, as shown:

Run the Ruletest and verify the results

Run the Ruletest by selecting Ruletest > Run All Tests.

Running the Ruletest sends the data on the Input pane to the rules engine. The rules engine fires the appropriate rules and displays the results in the Output pane. The first time rules are executed, they are automatically compiled from the rule model into an optimized executable form, then deployed into the engine, which may take a few seconds. Once deployed, the rules execute much faster on subsequent tests.

Check the outcome of your test in the TestSheet's Output pane.

Any attributes altered by the rules, including the entities to which they belong, are shown in bold text in the Output pane. Any unchanged attributes and values are displayed in normal style.

Messages contain the text of the Rule Statements and are shown in the Rule Messages pane. They are produced using the Post command in your Rule Statements. Severity indicates whether a message contains information, warnings, or violations. Message contains the text of the Rule Statement. Entity shows the entity to which this message is posted.

When you select the Cargo[1] entity within the Output pane, the first rule message is highlighted, showing the audit trail of rules that fired for that entity (in this case only one rule fired for Cargo[1]).

Use the Expected pane



So far, the actual results in the Output pane match the expected results in the Expected pane. To see what happens when the output does not match expected results, change one of the test cases. In the Expected pane, change the container value in Cargo[2] to standard.

Run the test again.

Your Ruletest should now look like this:



Here you see that Cargo[2] and the container attribute are highlighted red in both the Output and Expected panes, indicating that the output results differ from our expected results.

Remember to change the container value of Cargo[2] in the Expected pane back to oversize and save the test for future use by selecting File > Save.

Note: Corticon Studio highlights other types of differences also. For example, unexpected entities in the Output pane are highlighted in blue, while missing entities are highlighted in green in the Expected pane, as shown in the following example: