How to Unit Test a Decision Tree Rule
|
|
Proj-94 C-2409 C-1493 The Run Rule feature enables you to test a decision tree individually before testing it in the context of the application you are developing. B-17319 circumstance NORIR You specify a test page for the rule to use, provide sample data as the input, run the rule, and examine the results.
If you have the AutomatedTesting privilege (through an access role), you can use the features of Automated Unit Testing such as saved test cases and unit test suites for testing your decision tree. See About Automated Unit Testing and Working with the Test Cases tab for more information.
Before you begin
Before you begin, determine how you will provide the sample data to use when testing the rule. Can you provide all the data directly in the Run Rule window? Or does the rule need specific pages to be on the clipboard to return a decision?
- Examine the rule. Review the Applies To key part, Table tab and Pages & Classes tab of the rule, to identify the classes of the pages it uses for input and the properties involved in the decision.
- The Run Rule feature can create or copy a page to use as the test page, as appropriate for the rule you are testing. The page class of the test page is the Applies To class of the rule. If necessary, you can create a data transform to set initial values for the page.
- If the rule requires input from several pages, determine how to mimic the processing that creates them so the clipboard has the initial context you need to run the rule. For example, you can run an activity that creates the pages or start a flow and stop it at the appropriate point.
For general information about the Run Rule feature, including a list of the clipboard pages that are generated when a rule runs, see How to test a rule with the Run Rule feature.
Run the rule
To run the rule, complete the following steps:
- Save the rule.
- Complete any preprocessing necessary to create the appropriate clipboard context and, if the rule is circumstanced or time-qualified, to set the conditions you want to test.
- Click the Run button . The Run Rule window appears.
- In the Test Page section, specify which page to use as the main page: select Create or Reset Test page and in the Apply field, select the data transform to use for the test page or leave the default. Click Reset Page to clear any prior test data from the Results section of the window. B-20360 REJECTED
If you have the AutomatedTesting privilege and this rule has saved test cases, the Run Against a Saved Test Case choice is available. To run the rule and see how its behavior compares to that in its previously saved test cases, select a choice from the Run Against a Saved Test Case drop-down list. You can choose to unit test against a specific test case or all test cases.
After making your selection, click Run Test Case. If differences are found between results of running the current state of the rule and the saved test case, they are displayed and you have the options of overwriting the saved test case, viewing the rule history, and saving the results.
- In the lower section of the Run Rule window, enter the test data and click
Run Again. The system runs the decision tree and displays the results.
If you have the AutomatedTesting privilege and you want to save this run as a test case, click Save Test Case.
- Click Run Again as necessary, selecting other data transforms or providing other input values.
- Optional. Click the Result Decision Paths link to go directly to the row on the Decision tab that produced the test result. C-1637 NORIR
- Optional. Click Show Clipboard to open the Clipboard and examine the pages. Click the Hide Clipboard button to close the tool. B-20333 B-20454 rejected not refreshed For information about the clipboard pages that are generated, see How to test a rule with the Run Rule feature.
Debugging decision trees with the Tracer
C-446 If your decision tree does not give you the results you expect and you cannot determine the problem by running the rule and examining the clipboard pages, run the Tracer tool. With the Tracer you can watch each step in the evaluation of a decision tree as it occurs.
Complete the following steps:
- Click the icon in the Quick Launch area to start the Tracer. BYRNB 2/22/10
- In the Tracer window, click the Settings button ( ).
- In the Event Types to Trace section, select Decision Tree.
- Select the RuleSet that contains the rule to be traced. (Clear the other RuleSets to avoid memory usage from tracing events occurring in other RuleSets.)
- Click OK .
- Return to the main portal and run the decision tree.
- Watch the Tracer output as the rule runs.
About Decision Trees