/
Rule For: Rule Validation

Rule For: Rule Validation

Definition

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

errorWhen you expect an error, specify it in the cell to test that particular behavior
null / nothingWhen you expect a null value, put the keywords null or nothing to test that.
not nullWhen 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:


Green

 When the expected value matches the returned value, the RuleForInterpreter colors the cell as "right" by coloring it green.

Red

If the values don't match, the RuleForInterpreter colors the cell as "wrong" in red.

YELLOW

If the system encounters an execution error, the cell is colored yellow and GreenPepper provides information about the error.

Grey

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 forCalculator
xysum?product()quotient?
1001000
639-5

Output Table:

rule forCalculcator
xysum?product()quotient?
100100

0


java.lang.ArithmeticException: / by zero
com.greenpepper.samples.application.calculator.Calculator.quotient(Calculator.java:103)
639Expected:  -5  Received:  182


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 forDivision
  • 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 forinsurance 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 forDivision
    dividenddivisorquotient?
  • Example Mortgage : The given values for that example are the sale price and the down payment. The expected value is the premium fee.

    rule forinsurance premium fee calculation
    sale pricedown paymentpremium 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 forDivision
dividenddivisorquotient?
6.02.03.0
723.5
183.06
1528

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 forinsurance premium fee calculation
sale pricedown paymentpremium 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 forinsurance premium fee calculation
sale pricedown paymentpremium 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.

Related content

Rule For: Rule Validation (Developer)
Rule For: Rule Validation (Developer)
More like this
Do with: Workflow validation
Do with: Workflow validation
More like this
Do With: Workflow validation (Developer)
Do With: Workflow validation (Developer)
More like this
Documentation
Documentation
More like this
Setup: Context definition (Developer)
Setup: Context definition (Developer)
More like this
Specification Guide
Specification Guide
More like this