Sunday, January 1, 2017

How to unit test a data transform

The Run Rule feature enables you to test a data transform individually, before testing it in the context of the application you are developing.
Preparation
1.               Examine the rule. Review the Applies To key part, the DefinitionParameters, and Pages & Classes tabs of the rule to identify the classes of the pages it uses and the pages and properties involved in the data transform.
2.               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 (separate from the one you are testing) to set initial values for the test page.
3.               If the rule requires input from several pages, determine how to mimic the processing that creates them so the clipboard has the initial context (pages and properties) needed for the data transform. For example, if the Applies To class involves a work type, you can open a work item of the corresponding class to create and load relevant clipboard pages.
4.               For more comprehensive testing, create one or more additional data transforms that load various sets of input values into the clipboard.
Test approach
For basics of unit testing, see Unit testing a rule with the Run toolbar button.
1.               Save the Data Transform form.
2.               Click the Run toolbar button (Run) or the equivalent keyboard shortcut CTRL + R to open the Run Rule window. The Run Rule window opens.
3.               In the Test Page section, specify whether to pre-populate the main test page with values from another data transform before invoking the to-be-tested rule:
§  Select Create or reset Test Page and use the Apply Data Transform field to select a data transform to use to pre-populate the test page. If you do not make a selection, the system applies the default data transform of the tested rule's Applies To class (the pyDefault rule for that class).
§  Leave the default selection (Empty Test Page) to omit pre-populating the main test page with values.
4.               If the rule being tested is circumstance-qualified, select Set circumstance properties to run exact version of rule. Otherwise, the base version or a different circumstance-qualified version might be invoked other than the rule form from which you opened the Run Rule window.
5.               If Empty Test Page is selected, click Reset to ensure the test page on the clipboard is appropriately reset. If Create or reset Test Page is selected, the displayed button has one of the following labels:
§  Create Page (if this is the first test run and the test page does not already exist on the clipboard).
§  Reset Page (if the test page was created in a prior test run and exists on the clipboard).
Click the displayed button to ensure the test page is pre-populated according to the data transform specified in step 3.
6.               In the lower section of the Run Rule window, enter any test data (if any) needed by the tested rule, and click Execute to run the test.
Repeat as desired, selecting different data transforms to pre-populate the test page, or providing other input values.


2 comments: