Part 3: Testing with Faktor-IPS
Conceptual Foundation
In JUnit, usually the Java source code also contains the test data. There is no separation between the test logic and test data. As a result, you can’t reuse the same test logic for different test data. Because some Java knowledge is required to define test cases, this task can only be done by Java developers.
For business functions such as the calculation of insurance premiums, the separation of test data and test logic is a tremendous advantage because there are usually many test cases that vary only with respect to the test data. The following table illustrates this by showing three test cases on the premium computation described in the introductory tutorial.
Parameter | Test Case 1 | Test Case 2 | Test Case 3 |
---|---|---|---|
Product |
HC-Compact 2021-12 |
HC-Optimal 2021-12 |
HC-Optimal 2021-12 |
ExtraCoverages |
Bicycle Theft 2021-12 |
Bicycle Theft 2021-12 |
Overvoltage Damage 2021-12 |
PaymentMode |
annual |
annual |
annual |
ZipCode |
81673 |
81673 |
81673 |
SumInsured |
60.000 EUR |
60.000 EUR |
100.000EUR |
Expected Results |
|||
NetPremiumPm |
196,00 EUR |
208,00 EUR |
123,60 EUR |
All these test cases are processed in the same way:
-
A home contract is created based on the details of the product and the specified extra coverages. The attributes PaymentMode, ZipCode and SumInsured are populated with the values defined in the test case.
-
Next, the premium is computed by calling the appropriate method on the home contract.
-
The home contract’s NetPremiumPm is matched against the expected value that is defined in the test case.
Unlike JUnit, Faktor-IPS separates the test logic from the test data by distinguishing between test case types and test cases themselves. A test case type defines the control flow and the structure of the test data, whereas a test case instantiates a test case type with specific test data. The test data describe all input values that are required for the test, as well as the expected results.
Using OO terminology the test case type corresponds to a class and the test case itself is an instance of a test case type. This division is a simple means to foster the separation of roles during test development. The test case types are created by software developers who define the test data structure and write the test logic. Business users can then use these test case types to capture specific test cases with the respective test data.