Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

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.

fit1

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:

fit2

 

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.

fit3

 

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

fit4

 

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

Posted on Monday, November 19, 2007 4:19 PM | Back to top


Comments on this post: FIT, FITNESSE and FUN :)

# re: FIT, FITNESSE and FUN :)
Requesting Gravatar...
Hi Mohammad,
thanks for providing the link to my site, but I really suggest starting with the official fiitnesse.NET distribution, and then moving on to patches if you find that the additional functionality is useful. The link to download the main distribution is https://sourceforge.net/projects/fitnessedotnet

You might also be interested in my guide for FitNesse .NET programming on http://gojko.net/fitnesse/gettingfit
Left by Gojko Adzic on Nov 19, 2007 10:56 PM

# re: FIT, FITNESSE and FUN :)
Requesting Gravatar...
Hi Gojko Adzic,

I did download the DLL from the link that you provided but I could only get it to work with the patches. I will check out your guide.

Thanks,
Left by Mohammad Azam on Nov 20, 2007 8:43 AM

# re: FIT, FITNESSE and FUN :)
Requesting Gravatar...
Hi Mohammad,

Thank you for your interesting article.
I am new to both programming and fit(nesse).
I am a little confused of COMMAND_PATTERN. I'm using CppTestTools and Fitnesse. the command pattern {%m %p} doesn't work. What does it mean? Just for .NET?

I expect my fixture code will directly call some libs to test my software(in C language). So my Command patter is the executable file(actually my fixtures). But I got errors like:
java.lang.NoClassDefFoundError: fit/FitServer
Exception in thread “main”
Internal Exception:
java.lang.Exception: FitClient: external process terminated before a
connection could be established.
fitnesse.components.CommandRunningFitClient$
EarlyTerminationRunnable.run(CommandRunningFitClient.java:149)
java.lang.Thread.run(Unknown Source)

I don't use .Net. Could you please give me some advices to fix the problem?

Thanks in advance.

Jessica
Left by Jessica Jin on Nov 27, 2007 9:38 AM

# re: FIT, FITNESSE and FUN :)
Requesting Gravatar...

Hi Mohammad,

ur code is very useful & easy to understand...
but i want to implement my code in c language rather than .net can u please suggest me regarding the paths also...

Thanks in advance
pradeep
Left by pradeep on Dec 06, 2007 10:23 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net