The first test
One unit test for each rule
For the testing, a unit test has been created for each rule in the decision table.
We thus already have an initial test metric: 100% rule coverage.

We like to use Cucumber for unit testing. The generation of Gherkin feature files from decision tables is explained in the section Test case generation.
The feature file (Gherkin) used in this example when executing the unit tests:
# This file has been created by LF-ET 2.4.1 (260219a)
#
# Decision Table: \src\main\resources\lfet\demo\InvoiceTotal.lfet
# Rule selection and rule sorting: All rules, standard sorting
# Test cases with Errors: 0
# Test cases with Warnings: 0
# language: en
Feature: Calculate the invoice total
@recommended
Scenario: 0001 InvoiceTotal
InvoiceTotal
R01 : C01 Purchase order value = < 20.00
Given the shipping costs are EUR 5.72
When the order value is EUR 10.00
* the order process has been completed
Then no discount will be applied
* postage of EUR 5.72 is charged
* the total amount is EUR 15.72
@recommended
Scenario: 0002 InvoiceTotal
InvoiceTotal
R02 : C01 Purchase order value = 20.00 - 75.00 ; C02 Discount = >0 ; C03 Discount type = %
Given the shipping costs are EUR 6.12
When the order value is EUR 70.00
* a discount code with a value of 30 % has been entered
* the order process has been completed
Then a discount of EUR 21.00 is applied
* postage of EUR 6.12 is charged
* the total amount is EUR 55.12
@recommended
Scenario: 0003 InvoiceTotal
InvoiceTotal
R03 : C01 Purchase order value = 20.00 - 75.00 ; C02 Discount = >0 ; C03 Discount type = EUR ; C04 Discount < Purchase order value = Y
Given the shipping costs are EUR 6.12
When the order value is EUR 50.00
* a discount code with a value of EUR 33.32 has been entered
* the order process has been completed
Then a discount of EUR 33.32 is applied
* postage of EUR 6.12 is charged
* the total amount is EUR 22.80
@recommended
Scenario: 0004 InvoiceTotal
InvoiceTotal
R04 : C01 Purchase order value = 20.00 - 75.00 ; C02 Discount = >0 ; C03 Discount type = EUR ; C04 Discount < Purchase order value = N
Given the shipping costs are EUR 5.85
When the order value is EUR 20.01
* a discount code with a value of EUR 20.01 has been entered
* the value of the discount is greater than or equal to the order value
* the order process has been completed
Then no discount will be applied
* postage of EUR 5.85 is charged
* the total amount is EUR 25.86
@recommended
Scenario: 0005 InvoiceTotal
InvoiceTotal
R05 : C01 Purchase order value = 20.00 - 75.00 ; C02 Discount = none
Given the shipping costs are EUR 3.11
When the order value is EUR 50.00
* no discount code has been entered
* the order process has been completed
Then no discount will be applied
* postage of EUR 3.11 is charged
* the total amount is EUR 53.11
@recommended
Scenario: 0006 InvoiceTotal
InvoiceTotal
R06 : C01 Purchase order value = > 75.00 ; C02 Discount = >0
Given the shipping costs are EUR 8.40
When the order value is EUR 119.99
* a discount code with a value of EUR 60.00 has been entered
* the order process has been completed
Then a discount of EUR 60.00 is applied
* no postage is charged
* the total amount is EUR 59.99
@recommended
Scenario: 0007 InvoiceTotal
InvoiceTotal
R07 : C01 Purchase order value = > 75.00 ; C02 Discount = none
Given the shipping costs are EUR 9.66
When the order value is EUR 90.00
* no discount code has been entered
* the order process has been completed
Then no discount will be applied
* no postage is charged
* the total amount is EUR 90.00
### end of generated test cases ###
Result
After running the test, e.g., with the Maven command mvn clean verify, the result looks promising: BUILD SUCCESS.
Using the standard trace code in the rule modules, the following can be seen 'out of the box' in the console output:
-
the name of the decision table
-
the time stamp of program generation
-
the number of rules in the decision table
-
the number of the rule that has been executed
-
in our example also the state of the model BEFORE rule execution
The console log of test run:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running lfet.demo.InvoiceTotalTest
InvoiceTotal, 20260224.152032, 7, 1, InvoiceTotal_model(orderValue=10.00, orderDiscount=0.00, discountType=null, postage=5.72, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 2, InvoiceTotal_model(orderValue=70.00, orderDiscount=30.00, discountType=%, postage=6.12, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 3, InvoiceTotal_model(orderValue=50.00, orderDiscount=33.32, discountType=EUR, postage=6.12, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 4, InvoiceTotal_model(orderValue=20.01, orderDiscount=20.01, discountType=EUR, postage=5.85, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 5, InvoiceTotal_model(orderValue=50.00, orderDiscount=0.00, discountType=null, postage=3.11, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 6, InvoiceTotal_model(orderValue=119.99, orderDiscount=60.00, discountType=EUR, postage=8.40, totalPostage=0, totalDiscount=0, totalAmount=0)
InvoiceTotal, 20260224.152032, 7, 7, InvoiceTotal_model(orderValue=90.00, orderDiscount=0.00, discountType=null, postage=9.66, totalPostage=0, totalDiscount=0, totalAmount=0)
[INFO]
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.302 s -- in lfet.demo.InvoiceTotalTest
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------