Basic Fit Fixtures

Today we will discuss the  types of Basic FIT Fixtures and their table format.But before that please go through these links for better understanding.

  1. Fitnesse – Introduction
  2. Fitnesse Installation/ Environment Setup
  3. Sample project for Fitnesse
  4. Understand Fixtures and Usability Recommendations in Fitnesse

Following are basic fixtures in FIT

  • Column Fixture
  • Action Fixture
  • Row Fixture
  • Table Fixture
  •  Import
  • Summary Fixture


 ColumnFixture maps table columns directly to properties, methods and fields of the fixture class. It is very useful for repetitive verification for example-when same test needs to be repeated for different combinations of input arguments.

Table Format

The first row of the table is the test class name. The second row lists column names, specifying a field or method that the column is related to. Output values must have a question mark ?or parentheses ()after the field or method name.

!|info.fitnesse.fixturegallery.ColumnFixtureTest|
|firstPart|secondPart|together?|totalLength?|
|Hello|World|Hello, World|10|
|Houston|We Have a Problem|Houston, We Have a Problem|24|

Java Source Code

 package info.fitnesse.fixturegallery;
 import fit.ColumnFixture;
 public class ColumnFixtureTest extends ColumnFixture {
      public String firstPart;
      public String secondPart;
      private int length;
      public String together(){
           length=firstPart.length()+secondPart.length();
           return firstPart+ ", "+secondPart;
      }
      public inttotalLength(){
           return length;
      }
 }

Usage

======>>>Column Fixtureis great for describing calculation-based business rules and state machines. It should be used when the same type of calculation should be verified for a range of different input values, and user knows in advance all the different combinations.

ActionFixture was originally intended for workflow-style tests that are not repetitive. It uses a UI metaphor to automate other fixtures.

Table Format

The first row of an ActionFixture table always initializes the fixture class, in this case the ActionFixture itself and not a custom subclass. All rows after the first begin with a command cell, followed by command arguments in the remaining cells. Some rows will have two and some will have three cells. The second row is typically used for the start command, which expects one argument — the class name for the actual fixture to automate.

!|ActionFixture|
|start|ActionFixtureTest|
|enter|firstPart|Hello|
|enter|secondPart|World|
|press|join|
|check|together|Hello, World|

Java Source Code

 package info.fitnesse.fixturegallery;
 public class ActionFixtureTest extends fit.Fixture{
      private String first, second, both;
      public void firstPart(String s){
           first=s;
      }
      public void secondPart(String s){
           second=s;
      }
      public void join(){
           both=first+ ", "+second;
      }
      public String together(){
           return both;
      }
 }

Usage

=====>>ActionFixture is used to describe UI-style verification.

RowFixture tests dynamic lists of objects. It will compare the expected list (FitNesse table) with the actual result (from fixture code) and report any additional or missing items.

Table Format

The first row of the table is the fixture class name. The second row describes the structure of objects in the list (the properties or methods that you want to verify). All rows after that describe expected objects in the array.

!|RowFixtureTest|
 |name|postcode|
 |JohnSmith|SW466Z|
 |Michael Jordan|NE1 8AT|

Java Source Code

 packageinfo.fitnesse.fixturegallery;
 import info.fitnesse.fixturegallery.domain.Player;
 import fit.RowFixture;
 public class RowFixtureTest extends RowFixture{
      public Class getTargetClass() {
           return Player.class;
      }
      public Object[] query() throws Exception {
                return Player.players.toArray();
      }
 }

Usage

======>>Row Fixture is used to test and verify lists of objects, or to execute a method on every object in the list. Do not use RowFixture when the element order is important. (Use Array Fixture instead)

Table Fixture is an additional class in the FitNesse package. It is used to execute free-form tables that do not have a repetitive structure.

Table Format

With TableFixture, user can decide the format and which cells are actually used as part of the test. The only limitation is that the first row has to point to the class name of the fixture. This class can be used to turn existing invoices, reports or documents into FitNesse tests.

!|TableFixtureTest|
|Item|Productcode|Price|
|Pragmatic Programmer|B978-0201616224|34.03|
|Sony RDR-GX330|ERDR-GX330|94.80|
|Test Driven Development By Example|B978-0321146533|32.39|
|Net Total||161.22|
|Tax (10% on applicable items)||9.48|
|Total||170.70|

Java Source Code

 package info.fitnesse.fixturegallery;
 import info.fitnesse.fixturegallery.domain.TaxCalculator;
 import fitnesse.fixtures.TableFixture;
 public class TableFixtureTest extends TableFixture{
      protected void doStaticTable(int rows) {
           TaxCalculatortc=new TaxCalculator();
         double totaltax = 0;
         for (int row = 1; row < rows - 3; row++)
         {
      totaltax += tc.GetTax(getText(row, 1),
      Double.parseDouble(getText(row, 2)));
         }
         double taxintable = Double.parseDouble(getText(rows - 2, 2));
         if (taxintable == totaltax)
          right(rows - 2, 2);
         else
          wrong(rows - 2, 2,String.valueOf(totaltax));
        }
 }

Usage

===>>TableFixture is used when tests are in a business-specific table format that cannot easily work with any other fixture type. This is especially convenient if existing documents can be exported to HTML tables, since you can paste that HTML directly into FitNesse.

Import fixture can be used to tell FitNesse where to look for fixture classes. After importing a namespace or package it does not require fully-qualified fixture class names, thus making the tables more readable.

Table Format

The first row of the table should be Import. All following rows list namespaces or packages to import — one cell per row.

|Import|
|info.fitnesse.fixturegallery|

Usage

=====>>Import fixture is used to create test pages easier to read. It is a good practice to put this table into the SetUp pages for test suites.

Summary Fixture is a way to display a little bit of extra data on the page. Add a fit. SummaryFixture table at the bottom of a page and it will add a three-row table to the results, giving the standard counts for the page (right, wrong, ignored, and exceptions) as well as the run date and the run elapsed time for the fixture. Though it is not very useful, but handy when looking at a build report in order to message the relative efficiency and running time of each individual page.

In the next blog, we would discuss about another type of fixtures available ‘FitLibrary Fixtures’.

Shruti Shrivastava

Hey there, I'm Shruti Shrivastava. A Quality Engineer with an enthusiasm towards technical and non-technical writing. I've been into this profession for 3+ years now and thought of sharing my experiences and thus the fortunate turn of events has lead me to join Abode QA. When i am not glued to my system, i could be found reading novels, writing poems, enjoying with friends. Contact Me @ : shruti.shrivastava.in@gmail.com http://www.linkedin.com/profile/view?id=74986132&trk=nav_responsive_tab_profile

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.