Chapter 4. Test scenarios
Test scenarios in Red Hat Decision Manager enable you to validate the functionality of business rules and business rule data (for rules-based test scenarios) or of DMN models (for DMN-based test scenarios) before deploying them into a production environment. With a test scenario, you use data from your project to set given conditions and expected results based on one or more defined business rules. When you run the scenario, the expected results and actual results of the rule instance are compared. If the expected results match the actual results, the test is successful. If the expected results do not match the actual results, then the test fails.
Red Hat Decision Manager currently supports both the new Test Scenarios designer and the former Test Scenarios (Legacy) designer. The default designer is the new test scenarios designer, which supports testing of both rules and DMN models and provides an enhanced overall user experience with test scenarios. If required, you can continue to use the legacy test scenarios designer, which supports rule-based test scenarios only.
You can run the defined test scenarios in a number of ways, for example, you can run available test scenarios at the project level or inside a specific test scenario asset. Test scenarios are independent and cannot affect or modify other test scenarios. You can run test scenarios at any time during project development in Business Central. You do not have to compile or deploy your decision service to run test scenarios.
You can import data objects from different packages to the same project package as the test scenario. Assets in the same package are imported by default. After you create the necessary data objects and the test scenario, you can use the Data Objects tab of the test scenarios designer to verify that all required data objects are listed or to import other existing data objects by adding a New item.
Throughout the test scenarios documentation, all references to test scenarios and the test scenarios designer are for the new version, unless explicitly noted as the legacy version.
4.1. Testing the traffic violations using test scenarios
Use the test scenarios designer in Business Central to test the DMN decision requirements diagrams (DRDs) and define decision logic for the traffic violations project.
Figure 4.1. Test scenario for the traffic violations example
Prerequisites
- You have successfully built the traffic violations project in Business Central.
Procedure
- On the traffic-violation project’s home screen, click Add Asset to open the Add Asset screen.
Click Test Scenario to open the Create new Test Scenario dialog.
-
Enter
Violation Scenarios
in the Test Scenario field. -
From the Package list, select
com.myspace.traffic_violation
. -
Select
DMN
as the Source type. - Click the Choose DMN asset text field and select the path to the DMN asset.
- Click Ok to open the Violation Scenarios test scenario in the Test Scenarios designer.
-
Enter
- Under Driver column sub-header, right-click the State, City, Age, and Name value cells and select Delete column from the context menu options to remove them.
- Under Violation column sub-header, right-click the Date and Code value cells and select Delete column to remove them.
Enter the following information in the first row of the test scenarios:
-
Scenario description:
Above speed limit: 10km/h and 30 km/h
-
Points (under Given column header):
10
-
Type:
"speed"
-
Speed Limit:
100
-
Actual Speed:
120
-
Points:
3
-
Amount:
500
Should the driver be suspended?:
"No"
Right-click the first row and select Insert row below to add another row.
-
Scenario description:
Enter the following information in the second row of the test scenarios:
-
Scenario description:
Above speed limit: more than 30 km/h
-
Points (under Given column header):
10
-
Type:
"speed"
-
Speed Limit:
100
-
Actual Speed:
150
-
Points:
7
-
Amount:
1000
Should the driver be suspended?:
"No"
Right-click the second row and select Insert row below to add another row.
-
Scenario description:
Enter the following information in the third row of the test scenarios:
-
Scenario description:
Parking violation
-
Points (under Given column header):
10
-
Type:
"parking"
- Speed Limit: leave blank
- Actual Speed: leave blank
-
Points:
1
-
Amount:
100
Should the driver be suspended?:
"No"
Right-click the third row and select Insert row below to add another row.
-
Scenario description:
Enter the following information in the fourth row of the test scenarios:
-
Scenario description:
DUI violation
-
Points (under Given column header):
10
-
Type:
"driving under the influence"
- Speed Limit: leave blank
- Actual Speed: leave blank
-
Points:
5
-
Amount:
1000
Should the driver be suspended?:
"No"
Right-click the fourth row and select Insert row below to add another row.
-
Scenario description:
Enter the following information in the fifth row of the test scenarios:
-
Scenario description:
Driver suspended
-
Points (under Given column header):
15
-
Type:
"speed"
-
Speed Limit:
100
-
Actual Speed:
140
-
Points:
7
-
Amount:
1000
-
Should the driver be suspended?:
"Yes"
-
Scenario description:
- Click Save.
Click the Play icon to check whether the test scenarios pass or fail.
Figure 4.2. Test scenario execution result for the traffic violations example
In case of failure, correct the errors and run the test scenarios again.