The Analyze phase helped to ensure the logical integrity of our rules. The Test phase helps to ensure that our rules give us the correct business results. Let’s move on to testing.

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

media/image44.png

media/image45.png

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, we need to create a Ruletest file:

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

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


media/image49.png

As you can see, your new Ruletest is associated with the appropriate Rulesheet. This ensures that your Ruletest scenario will test the right rules.

Set up test cases

  1. Drag the Cargo entity from the Vocabulary and drop it anywhere in the Input as well as the Expected panes of the Ruletest.
    media/image50.png
    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 will cause an asterisk character to appear in the file’s tab. This is a reminder to save the file.
  2. Remove unneeded attributes by selecting them and pressing the Delete key. In our case, we remove manifestNumber from both Input and Expected as it is not needed to test these rules. media/image51.png
  3. Add test data for Test Case 1 to the TestSheet, as in this table. media/image52.pngTo do this, double-click the terms weight and volume in the Input column to enter their values. Then do the same in the Expected column, entering the container value as well.media/image53.png
  4. Enter the remaining test data based on the test cases in the table. media/image54.png

You can 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 this for the Expected pane. Use the tab key 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:

media/image55.png

The input column expects that all its container values are null. That is, if you click on container and enter nothing you still set a value as illustrated for Cargo [1]:

media/image56.png

To correct this, click on a container [] and then right click to choose Set to Null.

Run the Ruletest and verify the results

Run the Ruletest by selecting Ruletest > Run All Tests.

media/image57.png

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 will execute much faster on subsequent tests.

Next, check the outcome of your test in the TestSheet's Output pane.

media/image58.png

Any attributes that are 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 shown in the Rule Messages pane 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 we 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

media/image59.png

So far, the actual results in the Output pane match the expected results in the Expected pane. Let’s look at what happens when the output does not match expected results.

Let’s 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:

media/image61.png

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

Be sure 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 as well. Unexpected entities in the Output pane are highlighted in blue. Missing entities are highlighted in green in the Expected pane. Here’s an example:

media/image62.png