⇓ Get Latest Updates ⇓

Enter your email address:



Check email in your inbox for confirmation to get latest updates Software Testing for free.

⇓ Categories ⇓

Netsparker Web Application Security Scanner

Tutorial 9 - Using Slim Test Table Styles in Fitnesse

In previous FitNesse tutorials, we discussed and demonstrated examples related to the decision table. There are many other FitNesse tables which are yet to be explored. In this tutorial, we are going to discuss dynamic decision table in detail.

Dynamic Decision Table:

Decision table supplies the inputs and outputs for decision-making and marks the test as red or green color accordingly. Similarly, the dynamic decision table has the same syntax as decision table but it passes the column headers as parameters to the fixture in the form of Map or HashMap Java data structure. Syntactically, dynamic decision table has the first cell has to be prefixed by DDT: or dynamic decision:

To work with Query table, we need to do the following.

  • Don’t forget to mention DDT: in the first cell of the table. This statement informs the slim table processor that this is a dynamic decision table.
  • We can mention comments within any table column by starting the header name with a hash symbol (#).E.g. #description, etc. They are permitted in the dynamic decision table.
  • In this table structure, the column headers are passed as parameters that form the key of the HashMap used in the equivalent Java fixture.

    Using Slim Test Table Styles Fitnesse

  • The column without question mark is a setter. The cells with column headers that do not end with a “?” are considered inputs and they result in a method called set(header, value). The column values are passed along with the header value as a key to the setter method of the dynamic decision table as shown below in the Java fixture.
  • Like decision table, the column with a question mark is the getter where the returned result is compared the expected output. The cells with column headers that end with a “?”are considered outputs and they result in a method called get(header).
  • Other methods are similar to that of the Decision Table (table, beginTable, reset, execute, endTable).
  • Similarly, as in a Decision Table, all the set method calls are done before the execute call and all the get method calls are done after the execute call.

The explanation for Java Fixture:

  • Firstly the table name “dynamic decision table” matches with the class name declared as camel case “DynamicDecisionTable”.
  • We have declared a HashMap with the variable as COIN_EVAL. A Map in Java is the collection framework where data can be stored as key and value pair. Keys in Map cannot be duplicated and hence the columns present in the dynamic decision table.
  • In the HashMap, we have declared the underlying value for the each column identified as key with data type as a string. E.g. COIN_EVAL.put(“1p”, 1);
  • In the set method, we first look for the column header value passed by the dynamic decision table is present as a key in the declared Hashmap. If it is found then the corresponding value is captured in the Integer variable “amount”.
  • Logically, we are multiplying the column value passed into variable “amount” with the HashMap value retrieved against the key “coin” from the Map. This total is added with other occurrences into the variable “totalPaise”.
  • In the decision table, we are looking for the value of this variable “totalPaise” that forms the actual test and compares this result against the expected value present on the FitNesse page.
  • If the output result matches against the expected value, it is marked as green on the FitNesse page and if it does not match then with the red color.
  • If FitNesse does not find a fixture or throws null pointer exception then that would be shown in Yellow color.
  • Lastly, we have declared a get method where we are looking up for the column name (“Rs. total”) which is passed as input parameter to the getter method. When it matches, we are dividing the result present in variable “totalPaise” by 100 to form a rupee. (1 Rupee = 100 Paisa.)

This explains the entire Java fixture for the dynamic decision table which is shown below.

FitNesse Dynamic decision table1

 

FitNesse Screenshot for Dynamic decision table:

Our decision table displays the result as the response received from Java fixture class. Let’s discuss how we end up in below FitNesse page for Dynamic decision table.

  • Let’s take an example of first column with the actual test values. Here 1p = 5, 5p = 3, 10p = 6, 25p = 0, 50p = 0 and Rs.1 = 0. The set method identifies these values of the column along with the column header.
  • In the Java fixture, set method replaces the key values with the pre declared values in the Hash map. In the Hash Map these are the values which are pre-defined 1p =1, 5p = 5, 10p = 10, 25p = 25, 50p = 50 and Rs.1 = 100.
  • In the same method, we are doing the arithmetic operation where we are multiplying the HashMap values against the key with the column values passed from the FitNesse page. The output result is collected in the variable “totalPaise”. It is a simple calculation such as (5*1 + 5*3 + 10*6 + 25*0 + 50*0 + 100*0) = 80. Since the expected output for column “total paise?” is 80 and it matches the result, therefore, it is marked with the green color on the FitNesse
  • For the get method “Rs. Total?”, We are dividing the result with 100.0. It comes out to be 0.80 and matching the expected output. Hence marked with the green color.

    FitNesse Dynamic decision table2

  • Like decision table, we can store the value on the FitNesse page and can use that temporary value as an input value for the other tests on the same FitNesse page. In the above FitNesse page test, we are storing the output value for the 2nd test into the variable $totalPaise<-[2452].This stored value is used as an input in the third row against column “1p”.
  • In the third row of the test, we have created a test to check the lump sum value of the output result against the expected output which matched and marked as the green color [52~=34.5].

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>