Skip to main content Skip to complementary content

How to test a rule

About this task

You can define test cases for the rules you create. These test cases are stored in the repository and can be re-run to confirm that changes in any of the rule conditions have not created problems for example.

With this integrated testing process, users are kept involved in business rule development, testing, and maintenance.

In the following example, you want to create a test scenario to test the business rule created in Creating business rules.

To define a test case and run a testing process, complete the following:

Procedure

  1. From the Drools page, click Authoring and select Project Authoring.
  2. Click New Item and select Test Scenario to open the Create a new test scenario dialog box.

    Example

  3. Enter a name for the test scenario in the Test Scenario field, select the package that hold the business rule to be tested from the Package list and click OK.
    The test scenario editor opens in the workspace.

    Example

  4. Click the green + button next to GIVEN to open the New input dialog box and add a new data input to the scenario.

    Example

  5. Select LoanSimulator from the Insert a new fact list, set a fact name and click Add.
  6. In the test editor, click Add a field under the new fact name, select age from the dialog box that opens. Click OK.
    The age field is displayed under the fact name.
  7. Click the modify icon next to age and enter a value that is either smaller than 20 or greater than 70.

    Example

    This means the test will be done against this value.
  8. Click the green + button next to EXPECT to open the New expectation dialog box.

    Example

  9. Select the matching class and click the Add button next to the Fact value field.

    Example

  10. Click the text that is added to the editor, LoanSimulator[Toto] has values, and select rejected from the dialog box that opens. Click OK.
  11. Save your changes and click Run scenario.
    A confirmation message is displayed and the testing results are given in the Reporting panel and a log file is created in the editor.

    Example

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!