< Previous | Next >

Task 4: Testing rules

To validate rules and make sure that the changes have the effects that you want, you can test rules against scenarios. In this task, you create a scenario file to run tests on your rules.

Decision Validation Services (DVS) scenarios are use cases to validate the behavior of your rules. The scenarios and their expected results are stored in an Excel file called “scenario file”. The rules are executed against the scenarios and a report compares the expected results with the results obtained at execution time. The Excel scenario file contains two sheets:
Scenarios
To enter the test data in the columns created from the input parameters.
Expected Results
To define the results that you expect to get from the tests.

Business users can also create scenario files in Decision Center, but you must first prepare the rule project in Rule Designer.

To run the tests in Rule Designer or Decision Center, you must perform the following steps:
  • Validate the rule project and create an Excel scenario file to check the correctness of the output.
  • Enter test data in the Excel scenario files.
  • Run the tests in Rule Designer to ensure that the scenario file works as expected.

Time This task should take you about 20 to 30 minutes to complete.

Step 1: Select a constructor

The test data of the Excel scenario file is created from the ruleset input parameters. The BOM classes that make up the input parameters have constructors that define the columns in the Excel scenario file.

Before creating a scenario file, you must define the DVS constructor for the Borrower class. The DVS constructor that you select defines the mandatory columns.

In this tutorial, the name, credit score, and yearly income of the borrower are mandatory to test the rules.

To select a DVS constructor:

  1. In the Rule Explorer, double-click the Borrower class (my rule project > bom > miniloan > miniloan > Borrower).
    The Borrower class opens in the BOM Editor. In the Members section, you can see that the Borrower class has two constructors:
    • Borrower()
    • Borrower(String,int,int)

    The Borrower(String,int,int) is the constructor that contains the arguments that correspond to the name, credit score, and yearly income of the borrower. These arguments will be used to create the columns in the Excel scenario file.

  2. Double-click the Borrower(String,int,int) constructor to edit it.
  3. In the General Information section, select DVS constructor.

    This option specifies that the constructor must be used to create the columns of the Excel scenario file. The Borrower(String,int,int) constructor looks as follows in the BOM Editor:

    constructor
  4. Save the changes, and close the BOM editor.

You have defined the constructor to create the mandatory input columns for the borrower in the Scenarios sheet.

Note:

For the purpose of this tutorial, the DVS constructor of the Loan class is already selected for you.

The miniloan XOM contains annotations that specify the names of the constructor arguments, and indicates that Loan(int, int, double) is the constructor to use for testing. To view the annotations used, take a look at miniloan-xom/src/miniloan/Borrower.java and miniloan-xom/src/miniloan/Loan.java. For more information on annotations, see Adding annotations to the XOM.

Step 2: Validate the project

Before generating the Excel scenario file template, you must check that your project does not contain any errors or warnings that could prevent the generation of the Excel file.

To check your project:

  1. In the Rule Explorer, select my rule project.
  2. In the Rule Project Map, in the Design part, click Check project for testing.

    The DVS Project Validation view opens.

  3. Make sure that there are no errors or warnings.

    If no errors or warnings are listed, the project is valid and you can create a scenario file.

Step 3: Create a scenario file

After checking that your project does not contain any errors or warnings, you create an Excel scenario file template to validate the behavior of your rules.

To create the Excel scenario file:

  1. Switch back to the Rule Project Map and in the Deploy and Integrate part, click Create testing scenario file.
  2. In the Rule Project field, make sure that my rule project is selected, and then click Next.
  3. Select 2003 as the Excel version to use.
  4. Keep the Default Excel Format option.
  5. Select English (United States) as the language to use in the Excel file.
  6. In the Excel Scenario File Name field, change the name to /my rule project/miniloan-test.xls, and then click Next.
  7. On the Expected Results page, expand 'the loan', and select approved.

    The equals operator is displayed next to approved. The scenarios will test if the loan is approved.

  8. Click Next.
  9. Leave the Expected Execution Details page empty, and click Finish.

    In the Rule Explorer, the miniloan-test.xls is displayed under my rule project.

    Tip: If miniloan-test.xls is not displayed under my rule project, right-click the project in the Rule Explorer, and click Refresh.

Step 4: Populate the Excel scenario file

To check that the rule project is valid and that the Excel scenario file is correct, you enter two simple scenarios that you test later in this task:
  • Scenario 1 shows the original data from the Miniloan web application. The debt-to-income ratio is too high and the loan is rejected.
  • Scenario 2 shows that the amount of the loan is lower than in Scenario 1. The expected result is that the loan should be approved.

To populate the Excel scenario file:

  1. Outside of Eclipse, navigate to <MyEclipseWorkspace>/my rule project and open miniloan-test.xls.

    <MyEclipseWorkspace> refers to your workspace directory on the file system.

    If you use the Excel editor embedded in Eclipse, you might encounter difficulties to save the file.

    Tip: You can also right-click the file in the Rule Explorer, and click Open With > System Editor
  2. Complete the Scenarios sheet of the Excel scenario file template as follows:
    Tip:
    • To add rows, copy and paste the first one. Remember to change the name of the scenario that you have pasted.
    • In <InstallDir>/gettingstarted/DecisionServer/answer/miniloan-rules/, the miniloan-test.xls file is already completed with the following information.
    Table 1. Scenarios sheet
      the borrower the loan
    Scenario ID description name credit score yearly income amount duration yearly interest
    Scenario 1   Joe 600 80000 500000 240 0.05
    Scenario 2   Joe 600 80000 250000 240 0.05

    The amount of the loan is different between scenario 1 and scenario 2.

  3. Complete the Expected Results sheet as follows:
    Table 2. Expected Results sheet
    Scenario ID the loan is approved equals
    Scenario 1 FALSE
    Scenario 2 TRUE
  4. Save and close the file.
  5. In Rule Designer, right-click my rule project in the Rule Explorer and click Refresh to update the file.

Step 5: Test the Excel scenario file locally

To test that the scenario works as expected, you run the Excel scenario file locally in Rule Designer.

To test the Excel scenario file locally:

  1. On the Run menu, click Run Configurations.
  2. Create the configuration:
    1. In the side pane of the Run Configurations dialog, right-click DVS Excel File, and click New.
    2. In the Name field, enter Miniloan Test as the name for the launch configuration.
    3. In the Excel File field, click Browse, select my rule project/miniloan-test.xls, and click OK.
    4. In the Rule Project field, click Browse, select my rule project, and click OK.
    5. In the HTML Report field, click Browse, select my rule project, and click OK.
    6. Click the DVS Configuration tab, and make sure that the Local execution option is selected.
  3. Click Apply, and then Run.
    The Console view shows a log of the build process, and the following result:
    --- Output for scenario 'Scenario 1' : 
    false [Too big Debt-To-Income ratio]
    --- Output for scenario 'Scenario 2' : 
    true []
    Execution finished
    If the Console view does not open automatically, click Window > Show View > Other, then select General > Console, and click OK.
  4. In the Rule Explorer, right-click my rule project and click Refresh.

    The report.html file is displayed under the project.

  5. In the Rule Explorer, right-click report.html, and click Open With > Web Browser.

    The report opens and shows the results of the tests: the execution results are the same as the expected results. The tests are successful.

    Report

    In Scenario 1, the loan is rejected, as specified in the expected results (the loan is approved equals: FALSE).

    In Scenario 2, the loan is approved, as specified in the expected results (the loan is approved equals: TRUE).

  6. Close the report.

Now that you have made some changes to the BOM, in the next task you will see how to debug the rule project using the Excel file.

< Previous | Next >