Building a better software depends heavily on how well you communicate with your client. Unfortunately, most of the clients are not tech savvy and hence the domain logic becomes a communication barrier between the client and the developer. If only there was such system that could easily be understood by both the clients and the developers. FIT tries to minimize this gap by introducing the table based structure hence minimizing the gap between the two species.

Introduction:

Building a better software depends heavily on how well you communicate with your client. Unfortunately, most of the clients are not tech savvy and hence the domain logic becomes a communication barrier between the client and the developer. If only there was such system that could easily be understood by both the clients and the developers. FIT tries to minimize this gap by introducing the table based structure hence minimizing the gap between the two species.

What is FIT?

FIT stands for (Framework for Integrated Tests) and it allows the developers to work closely with the clients. The reason for this closeness is not love or affection but the simplicity of FIT and Fitnesse to parse and produce results understandable by the clients.

What is Fitnesse?

Fitnesse is a tool which uses the Fit framework to produce readable results. It is a Wiki which allows the developer to create their pages and edit the content. I will explain the details later in the article.

Installing Fit and Fitnesse?

I will be honest with you I had a hard time finding the correct .NET 2.0 compatible DLL. I don’t want my readers to go through the same experience hence I am posting the URLS below:

Fit: http://fit.c2.com/wiki.cgi?DownloadNow

Fitnesse: http://gojko.net/FitNesse/fdnpatch20070322-binaries.zip

If you notice the Fitnesse download is a binary patch. I got my tests working using this patch.

Discussing the Scenario:

Before we dive into the Fit and Fitnesse details let’s first talk about the scenario that we are going to solve. Our client needs a simple application that will keep track of the check-in and check-out time of the employees. The application will also display the pay rate, number of hours worked and the pay collected for the day.

The first thing you need to do is to schedule a meeting with the client in which you will discuss the details of the application. During the meeting you will draw a table to show sample data. The drawing of table on the paper is your communication with the client. You won’t open an IDE and start typing the unit tests because the client won’t understand the code. You can however communicate with the client using a spreadsheet since most of the people understand the table layout. Check out the image below where the developer and the client discusses the application using excel spreadsheet.

 

The above excel spreadsheet describes what the client wants in the application. This is the expectation of the client or the client’s view of the application. Now, that we have the basic idea of the application and also some sample data we can write tests against the data provided by the client.

Starting the Fit Server:

First, you need to start the Fit Server. Simply browse to your fit folder and find the “run.bat” file. Now, using command line issue the following command: 

This will start the fit server on port “8888”. To verify that the fit server has started browse the following URL:

http://localhost:8888/

You will see the homepage for Fitnesse:  

Good! You got fit server running and you got Fitnesse setup to run the tests. Now, let’s export our data from excel to the Fitenesse page.

Creating a New Page for Tests:

It is a good idea to organize your test hence we are going to create a new page for our TimeSheet tests.

Type the following in your address bar:

http://localhost:8888/timesheet

You will see the following result: 

This is interesting! Fitnesse should have asked us to create a new page since it does not exist. Let’s try a different approach:

http://localhost:8888/TimeSheet

This time you will see the following page:

Interesting! Now, it displays the options to create this page. It seems like Fitnesse follows the two word format in which both words are joined together with their first letter capitalized like FooBar, HelloWorld, ByeBye, SomeThing etc.

When you click on the “create this page” you will be redirected to a page with a large textbox so you can enter your expected data. 

Editing the Edit Page:

The first thing you need to do is to copy and paste the excel file which you and the client created into the “Edit Box”. 

The above image shows the data I just copied and pasted from excel into the Edit Box. Now, click on “Spreadsheet to Fitnesse” button and it will convert the data into a Fitnesse format. 


 
I know I have pasted a lot of things in the Edit Box so let me explain all of them. First the excel data is converted into the Fitnesse format which looks like the following:

|checkintime|checkouttime|rate|hoursworked?|pay?|
|9:00 AM|5:00 PM|7|8|56|
|10:30 AM|12:30 PM|4|2|8|
|9:45 AM|12:30 PM|10|2.45|24.5|
|9:05 PM|3:30 PM|7|6.25|43.75|

Then I placed the name of the class above it. This will be the class in C# or VB.NET.

!|Timesheet|
|checkintime|checkouttime|rate|hoursworked?|pay?|
|9:00 AM|5:00 PM|7|8|56|
|10:30 AM|12:30 PM|4|2|8|
|9:45 AM|12:30 PM|10|2.45|24.5|
|9:05 PM|3:30 PM|7|6.25|43.75|

Finally, I pasted some configuration settings.

!define COMMAND_PATTERN {%m %p}

(The COMMAND PATTERN tells Fitnesse to start Java. You can also use Python by supplying the following command pattern
 !define COMMAND_PATTERN {python "%m" %p}
)

!define TEST_RUNNER {C:\Documents and Settings\Azam\Desktop\fdnpatch20070322-binaries\dotnet2\FitServer.exe}

This is the path for the dotnet2 assembly which helps us to run tests against .net 2.0 framework.

!path C:\Projects\DemoFIT\DemoFITSolution\TestLibrary\bin\Debug\TestLibrary.dll

The library which contains the tests.

Click the “Save” button and you will see our data in a table format as shown in the image below: 

Now, let’s create the C# class which will run these tests.

Creating the Testing Class:

Create a class library project and then add a class named “Timesheet” (This is the same name we used in your Fitnesse edit box). Add a reference to the fit.dll. Your class “Timesheet” must inherit from the ColumnFixture class as shown below:

public class Timesheet : ColumnFixture

Let’s check out the complete implementation of the Timesheet class:

using System;
using System.Collections.Generic;
using System.Text;
using fit;

    public class Timesheet : ColumnFixture
    {
     
        public DateTime checkintime;
        public DateTime checkouttime;
        public double rate;
       
        public double pay()
        {
            return (rate * hoursworked());
        }

        // returns the number of hours worked
        public double hoursworked()
        {
            TimeSpan t = checkouttime.Subtract(checkintime);
            double s = ((double)t.Hours) + ((double) t.Minutes / 100);
            return s;
        }

    }

I have used public variables to represent the columns in the Fitnesse table and methods to represents the “?” (expected) data. I have two methods “pay” and “hoursworked”.

Now, let’s see how to run tests.

Running the Tests:

Browse to the http://localhost:8888/TimeSheet page and click on properties. Now, check the “Test” checkbox and click “Save Properties”. Now, you will see a “Test” button on the left side of the menu. Click the test button and it will run the tests. Here are my results after running the tests. 

You can see from the image above that one of my tests failed. This is failed because I accidentally entered the wrong data. The input “9:05 PM” should have been “9:05 AM”. Once, you have corrected the data all the tests will pass successfully.

Conclusion:

Fit and Fitnesse allows the clients and developers to communicate in an understandable format. This results in a better software and hence happy clients and developers.

I hope you liked this article! Happy coding!