Yesterday I had fun trying out Fit and Fitnesse. For those who are not familiar with Fit and Fitnesse, Fit stands for Framework for Integrated Test and Fitnesse is a tool to run Fit tests. The idea behind Fit is to create a communication bridge between the developers and the managers or the clients. For this we need some interface which can be understood by a non-technical person. Fit handles this problem by creating a HTML table interface. The table can be created in Word, Excel or manually. Take a look at the simple table which shows the basic addition of two numbers.

This table can be easily created by the customer explaining the developer how the addition should work. Now, the developer has some idea about the application. The application consits of two numbers and a result. When 2 + 3 then the result is 5. This excel data can serve as a template for building strong test cases.
Now, it is time to use Fit and write tests. First you need to download Fit from the above link. For Fitnesse you can download using this link. I had hard time building this example because the Fitnesse version was not compatible with .NET 2.0. Finally, I found the version that is compatible and it worked.
OK! Let's first start the Fit server. open up the command prompt and browse to your Fit folder where you can see "run.bat" file. Now, you type on the command prompt:
run.bat -p 8888
The above line means that you are starting the Fit server on port 8888. To make sure that the server has started browse to the following location.
http://localhost:8888/
You will see the homepage for Fitnesse as show below:

Good so far! Now browse to the page http://localhost:8888/HelloWorld
Fitnesse will ask you to create this page and yes create it!
Now, click on the "Edit" button on the right of the screen. Copy the excel data (literally copy it by dragging your mouse over it and right click and copy) and paste it in the Textbox on the "Edit" screen. Then you can click Spreadsheet to Fitnesse and this will format the data.
It will look something like this:
|number1|number2|add?|
|2|2|4|
|1|2|3|
|5|5|10|
OK! I am going to paste the complete code here so don't freak out. I will explain all the details. This is the code that you will put in the "Edit" box on the Fitnesse page.
!define COMMAND_PATTERN {%m %p}
!define TEST_RUNNER {C:\Documents and Settings\Azam\Desktop\fdnpatch20070322-binaries\dotnet2\FitServer.exe}
!path C:\Projects\DemoFIT\DemoFITSolution\TestLibrary\bin\Debug\TestLibrary.dll
!|Addition|
|number1|number2|result?|
|2|2|4|
|1|2|3|
|5|5|10|
OK! Now, let me explain it. The first line is some command pattern you don't have to worry about it. The second line
!define TEST_RUNNER {C:\Documents and Settings\Azam\Desktop\fdnpatch20070322-binaries\dotnet2\FitServer.exe}
describes the path to the FitServer.exe file which is used to process the .NET 2.0 code.
The third line is the path to your Class Library project which contains the logic of the test.
!path C:\Projects\DemoFIT\DemoFITSolution\TestLibrary\bin\Debug\TestLibrary.dll
!|Addition| is the name of the class. The rest four lines are just copied from the excel.
Cool right!
Now, let's go and create a class library project and add a class called "Addition". Here is my "Addition" class:
using System;
using System.Collections.Generic;
using System.Text;
using fit;
public class Addition : ColumnFixture
{
public int number1 = 0;
public int number2 = 0;
public int result()
{
return (number1 + number2);
}
}
First thing first, add a reference to the "fit.dll" that is contained in the C:\[Your Path]\fdnpatch20070322-binaries\dotnet2\fit.dll folder. Make sure the folder is "dotnet2". As, you can see the Addition class mimics the columns provided by the user. The Addition class derives from the "ColumnFixture" class. It has public fields "number1", "number2" and the method "result". Make sure that you create the variables with the same name as the data you provided to the Fitnesse.
OK! everything is good and the final thing is to run the test. But wait! where is the "Test" button on the Fitnesse page. Browse to the following page.
http://localhost:8888/HelloWorld
On the left hand side click on "Properties" and then check mark the "Test" option. Now, you will have the "Test" as the first option on the menu. Click on the "Test" and the tests will be executed. Take a look at the screen shot below which shows the tests result.

And below is the image where the test fails. I purposely added "1" to my addition method and hence the output is incorrect.

I hope you enjoyed this post! I will write an article on this topic very soon which will be hosted on www.koffeekoder.com.