Rule For: Rule Validation
Definition
The RuleForInterpreter is used to express concrete and measurable business rules.
During the execution of the specification, GreenPepper compares the values returned by the system under development against the expected values defined by the Business Expert.
- The first row of the table indicates the set of rules to be tested by GreenPepper.
- The next row is called the header row and serves to distinguish the given values and the expected values. Given values serve as input to the system, whereas expected values serve as comparison values against values that are actually returned by the system. When a column header ends with special characters ? or (), it denotes an expected value.
- Finally, the remaining rows capture the examples. They are the executable test rows.
Specific Keywords for expected values
GreenPepper offers a list of useful keywords to support the Business Expert.
<<Empty cells>> | When a test cell is left blank, GreenPepper only shows the returned value |
---|---|
error | When you expect an error, specify it in the cell to test that particular behavior |
null / nothing | When you expect a null value, put the keywords null or nothing to test that. |
not null | When you expect a not null value but can't assess the exact value, use the not null keyword. (since GP 4.1.7) |
Coloring
GreenPepper will visually show the test result by coloring each testing cell:
When the expected value matches the returned value, the RuleForInterpreter colors the cell as "right" by coloring it green.
If the values don't match, the RuleForInterpreter colors the cell as "wrong" in red.
If the system encounters an execution error, the cell is colored yellow and GreenPepper provides information about the error.
If no expected value is specified in a test, the RuleForInterpreter colors the cell in gray.
Here is an example of cell coloring:
Input Table:
rule for | Calculator | |||
---|---|---|---|---|
x | y | sum? | product() | quotient? |
10 | 0 | 10 | 0 | 0 |
6 | 3 | 9 | -5 |
Output Table:
rule for | Calculcator | |||
---|---|---|---|---|
x | y | sum? | product() | quotient? |
10 | 0 | 10 | 0 | 0 java.lang.ArithmeticException: / by zero |
6 | 3 | 9 | Expected: -5 Received: 18 | 2 |
Writing a Rule For Specification
When do we use the RuleForInterpreter?
The RuleForInterpreter is used to express concrete and measurable business rules. The business rules are often related to all kind of calculations.
When a table of rule is executed, GreenPepper compares the values returned by the system under development against the expected values defined by the Business Expert.
First row: Identification of the Rule For
In a Rule For table, the first row specifies the name of the interpreter and the name of the rules to be tested.
The business expert should be clear in the identification of the set of rules.
Example Division : A simple system performing divisions. In that particular case, we could define the set of rules as Division which leads to:
rule for Division
Example Mortgage : A Mortgage management system with the following specifications:
"Whenever the down payment on the property is less than 25% of the sale price, the buyer has to pay a premium for insuring the mortgage. The premium fee amount is 2.5% of the financed amount (which is sale price - down payment)."
For that particular calculation we could identify the set of rules as:rule for insurance premium fee calculation
Second row: the Header
The second row is called the header row and serves to distinguish between the given values and the expected values. Given values serve as inputs to the system, whereas expected values serve as comparison values against values that are actually returned by the system. When a column header ends with special characters ? or (), it denotes an expected value.
Example Division : The given values for that example are the dividend and the divisor. The expected value is the quotient.
rule for Division dividend divisor quotient?
Example Mortgage : The given values for that example are the sale price and the down payment. The expected value is the premium fee.
rule for insurance premium fee calculation sale price down payment premium fee?
Third and following rows: Examples
The remaining rows capture the examples. They are the executable test rows.
Final expression of the Division example
rule for | Division | |
dividend | divisor | quotient? |
6.0 | 2.0 | 3.0 |
7 | 2 | 3.5 |
18 | 3.0 | 6 |
15 | 2 | 8 |
Final expression of the Mortgage example
Specification: "Whenever the down payment on the property is less than 25% of the sale price, the buyer has to pay a premium for insuring the mortgage. The premium fee amounts is 2.5% of the financed amount (which is sale price - down payment)."
rule for | insurance premium fee calculation | |
sale price | down payment | premium fee? |
$100,000 | $15,000 | $2,125.00 |
$100,000 | $30,000 | $0.00 |
$100,000 | $25,000 | $0.00 |
When there is no expected value specified in a cell, GreenPepper provides the value calculated by the system under development. The business expert could use that functionality to facilitate the comprehension of a rule. In this example, the financed amount of mortgage can be evaluated as an intermediate result.
rule for | insurance premium fee calculation | ||
sale price | down payment | premium fee? | financed amount? |
$100,000 | $15,000 | $2,125.00 | |
$100,000 | $30,000 | $0.00 | |
$100,000 | $25,000 | $0.00 |
Execution of specifications
Based on those executable specifications, the developers are now ready to code the functionality and the fixture (the fixture is the link between the system under development and the executable specification). Once this is done, the specification can be executed by clicking on the Execute button on the top of the page.
During execution, GreenPepper colors only the cells of the column "expected values". GreenPepper will color the cell green if the returned value equals the expected value. If the returned value is not the same, GreenPepper will color the cell red and will show the expected and the returned values. Finally, if an expected value is left blank by the business expert, GreenPepper colors the cell in gray, to display that no test was performed, and shows the returned value.
The examples provided in this page are used to explain how to write the fixture for the RuleForInterpreter.