Creating and Running a Test Case

Use

You can test the correctness and effectiveness of the rules before you deploy and execute them by creating test cases.

In a test case, you use a CSV file to capture multiple sets of simulated data for testing.

Procedure

Creating a Test Case Folder

Test Case folders help you categorize test cases.

  1. Locate the Test Cases node ( Where is the Test Cases node? ) and in the context menu of the Test Cases node, choose New Folder .

  2. In the dialog box that appears, enter the name of the folder and choose OK .

When you expand the Test Cases node, you should see the test case folder.

Creating a Test Case
  1. Locate the Test Cases node ( Where is the Test Cases node? ) and in the context menu of the Test Cases node or test case folder node, choose New XML Test Case .

  2. In the dialog box that appears, enter the name of the test case and Choose OK .

    You should see the test case when you expand the Test Cases node or test case folder node. The test case editor appears.

Setting the Target Ruleset
  1. In the Test Case editor, choose the Setup tab, in the tab page that appears, locate Target Ruleset: and in the drop down menu choose a ruleset.

  2. Save the changes.

Creating the XML Document

You create an XML document based on the XML schema you used to write your rules. The XML document contains the data for the test case.

x`

  1. In the Test Case editor, choose Create XML in the top right corner.

  2. In the dialog box that appears, the Choose XSD radio button is selected by default. Select the XML schema of your choice.

  3. Choose OK .

  4. In the screen that appears, in the File name: field enter a name for the XML document.

  5. Choose Next . In the screen that appears, accept default selections or change the selections according to your choice.

  6. Choose Finish .

    In the Project Explorer view, you should see the XML document when you expand the src and brmstests nodes. The XML document opens in the Design view of the editor window.

Adding the XML Document to the Test Case
  1. In the Test Case editor, in the XML Documents for Test Input section, choose the Add XML button

  2. In the dialog box that appears, select the checkbox referring to the XML document you created and choose OK .

  3. The XML document gets listed in the XML Documents for Test Input table.

  4. Save the changes

Creating the Data Source

The data source is a CSV file that contains the input data and expected output data for testing the correctness of your rules.

  1. In the test case editor, choose Create Data Source in the top right corner.

  2. In the dialog box that appears, enter a name for the data source and choose Finish .

    The data source opens in the editor window. You should see a blank window.

  3. Enter data in the editor window.

    Here is an example of a data source (CSV file):

  4. Save the changes.

Adding the Data Source as Test Data
  1. In the test case editor, in the Test Data section, choose the Set Data Source button.

  2. In the dialog box that appears, choose a data source file in the drop down menu and choose OK .

Mapping XPath to Constant Values or Header Names in the Data Source

When you run the test case, the values from the data source must be taken as input data and expected output data. So you need to map the XML elements you have used in your rules with the header names in the data source. When you map the output data you compare the expected output with the actual output using a comparator. This indicates if the test case has failed or passed.

  1. In the test case editor, choose the Detailed Configuration tab.

  2. In the tab page that appears, in the Input Mapping section, select the root element and choose the Add XPath button.

  3. In the dialog box that appears press Ctrl and choose all the elements that you want to set as input data for the test case and press the Select Actions button. Choose OK.

  4. Choose the Add Definition button to add a definition as input data for the test case.

  5. In the dialog box that appears, choose Project Resources or a ruleset name in the drop down menu. All definitions in the ruleset or Project Resources appear.

  6. Select a definition checkbox and choose OK .

  7. In the Input Mapping section, in the table, the Mapping Element column displays the definitions and XML elements you added.

  8. Choose the corresponding cell to each element or definition in the Mapping Element column, and in the drop down menu you should see all the header names as specified in the data source. Make sure the header name you choose is the same as the XML element or definition.

  9. Repeat the step until you map all the XPaths with the header names.

  10. In the Output Mapping section, add the XML elements or definitions you want to set as output data for test case

    In the table, the Mapping Element column displays the definitions and XML elements you added.

  11. In the Comparator column choose a comparator in the drop down menu.

  12. In the Value column , enter a constant or choose a header in the drop down menu.

  13. If the output of the test case is a numerical value, you can use the cell in the Formatter column to specify the format of the numerical value such as #.# . #.## , ###,###.### , 000000.000 , $###,###.### and so on.

Setting Custom Properties
  1. In the test case editor, in the Custom Properties section, you should see two options:

    • Use first data row of data source as default value : This option indicates that when no value is available for a column in a data row (for data source), the first row value for that column is used if set to true, otherwise value is taken as "".

    • Maximum number of failed data rows with trace details : This options allows you limit the number of trace details (for failed test data) to be displayed in test report .

Running the Test Case
  1. In the test case editor, choose Run Test Case in the top right corner.

    In the Rule Testing Console window, you should see the location of the test case report. Access the report in the specified location.