Latest Tweets

Acceptance Testing with FitNesse and .Net

FitNesse

What is FitNesse?

It's a colaboration and communication tool that allows the clients, testers and developers give an answer to the ultimate question of life, the universe, and everything else... and it's not 42.

Well, maybe not that much =). It allows to describe what a piece of sofware should do and compare the results with what it really does, matching the client's real expectations.

FitNesse is a software testing tool. From this point of view, it allows the developing team to colaborate in the acceptance test definition in simple HTML tables in a wiki, run those test and check the results.

Installing FitNesse

Installing and running FitNesse in a Windows enviroment to run a .NET Acceptance Test is an easy 3 step procedure + a plugin instalation:

  1. Be sure to have the latest Java VM, you can check this here and the latest Microsoft .Net Framweork here, if you have Visual Studio 2008 or up installed, this late check is not necessary.
  2. Download the latest fitnesse.jar from here to an easy to remember folder, in my case it was d:\FitNesse
  3. Run the following command: D:\FitNesse> java -jar D:\FitNesse\fitnesse.jar

Notes:

  • Java's bin folder must be already added to your PATH environment variable.
  • If you have a web sever running on the port 80 (like IIS default instalation) you will need to add -p 8080 (or another port) to the command.

In my case, I had to execute:

D:\FitNesse> java -jar D:\FitNesse\fitnesse.jar -p 8080

The first time, it will try to download and install some updates, so be patient. At last you will have a response like:

FitNesse Server running

Leave this console open. To test if FitNesse is running, using ${insert_the_browser_of_your_choice} go to http://localhost (or in my case http://localhost:8080)

FitNesse Welcome page

Now, we need the .NET plugin from here called FitSharp, download the latest version or the one that is relevant to you (you have different plugins trageting different .net framework versions) and expand it. In my case: d:\FitNesse\Fitsharp. You can expand it elsewere, but is easier to mantain it if you keep it in that location (d:\FitNesse\FitSharp).

How does it works?

Fit is the test engine responsible of executing the test. It just reads the HTML tables and uses the data on those tables to execut the test and compare the actual results against the expected ones.

We will need a thin integration layer on top of our .NET code that will provide the entry points to the actual business objects and their methods and properties that will be mapped to the test data and expected results. Tipically, this integration layer is a set of C# classes that extends Fit.Fixture or any other derived class from it.

Acceptance Test

Let's start with an example.

  • Open Visual Studio and create a Class Library Project named FitnesseIntegrationDemo where our "business objects" will live.
  • Add a reference to fit.dll and fitsharp.dll (D:\FitNesse\FitSharp).
  • Add a class named OutFirstTest with the following code and compile the project.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FitnesseIntegrationDemo
{
    public class OurFirstTest :  fit.ColumnFixture
    {
        public int hourValue;
        public int workedHours;
        
        public int CalculateGrossSalary()
        {
            return hourValue * workedHours;
        }
    }
}
  • Copy the generated output dlls to D:\FitNesse\FitIntegrationDemo

Such page does not exsist, but, since FitNesse works as a wiki, it will be automatically created. Copy the following code on the editor and save it:

!contents -R2 -g -p -f -h
!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,D:\Fitnesse\FitSharp\fit.dll %p}
!define TEST_RUNNER {D:\Fitnesse\FitSharp\RunnerW.exe}
!path D:\Fitnesse\FitnesseIntegrationDemo\FitnesseIntegrationDemo.dll

!|FitnesseIntegrationDemo.OurFirstTest|
|hourValue|workedHours|CalculateGrossSalary?|
|160|40|6400|
|160|25|4000|

FitNesse was originaly developed to run Java test, the first two lines tell FitNesse wich TestRunner must use (FitSharp)

!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,D:\Fitnesse\FitSharp\fit.dll %p}
!define TEST_RUNNER {D:\Fitnesse\FitSharp\RunnerW.exe}

The third line specify where the test clases are located (the thin integration layer)

!path D:\Fitnesse\FitnesseIntegrationDemo\FitnesseIntegrationDemo.dll

Then, we will find the table definition with the class, method that is going to be executed and the data that is going to be used for testing and comparison.

The first line is the Class that is going to be instantiated:

!|FitnesseIntegrationDemo.OurFirstTest|

This class inherits from ColumnFixture, it maps the properties and methods to columns, then, the next line we have the properties and the method to execute

|hourValue|workedHours|CalculateGrossSalary?|

The following rows contains the data test and the expected results

|160|40|6400|
|160|25|4000|
  • Now, on the left menu, click on Properties, change the page type to Test and save your changes. When the page is reloaded, you will be able to see a new button Test

FitNesse Integration Demo Test page

  • Click on Test and see the results

FitNesse Integration Demo Runt Test page

Part of this guide is extracted from here. I do recomend to go there and read it, there are some more detailed examples and an excellent PDF document you can download for future reference.

If you find that the test is not running or it hangs forever, please verify the sintax of the page (casing and spaces). It may be also useful to change the TestRunner to RunnerW.exe. It will popup a windows where all the exceptions are going to be shown (don't forget to click con Go). I've spent more than 4 hours chasing a small stupid error on the test's first line (shame on me!) =)

That's all folks, happy acceptance testing! =)

Author

Project Manager
Seasoned Professional with 15+ years experience on the Technology Industry.

Add comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.