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 a 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.
FIT stands for (Framework for Integrated Tests) and it allows developers to work closely with 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.
Fitnesse is a tool which uses the Fit framework to produce readable results. It is a Wiki which allows developers to create their pages and edit the content. I will explain the details later in the article.
I will be honest with you. I had a hard time finding the correct .NET 2.0 compatible DLL. I don’t want readers to go through the same experience, hence I am posting links to the URLs below:
If you notice, the Fitnesse download is a binary patch. I got my tests working using this patch.
Before we dive into the details of Fit and Fitnesse, 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 the table on 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 people understand the table layout. Check out the image below where the developer and the client discuss the application using an 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.
First, you need to start the Fit server. Simply browse to your Fit folder and find the run.bat file. Now, using the 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:.
You will see the homepage for Fitnesse:
Good! You got the Fit server running and you got Fitnesse setup to run the tests. Now, let’s export our data from Excel to the Fitnesse page.
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:.
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:.
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 “Create this page”, you will be redirected to a page with a large textbox so you can enter your expected data.
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 .NET 2.0 assembly which helps us to run tests against the .NET 2.0 Framework.
!path C:\Projects\DemoFIT\DemoFITSolution\TestLibrary\bin\Debug\TestLibrary.dll
This is 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.
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 fit.dll. Your class Timesheet must inherit from the ColumnFixture class as shown below:
Timesheet
ColumnFixture
public class Timesheet : ColumnFixture
Let’s check out the complete implementation of the Timesheet class:
Timesheet
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.
Fitnesse
pay
hoursworked
Now, let’s see how to run tests.
Browse to the 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 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.
Fit and Fitnesse allows clients and developers to communicate in an understandable format. This results in better software and hence happy clients and developers.
I hope you liked.