Integration Testing With Fitnesse

Fitnesse is an application testing tool that allows you to test your business logic. As the name FITnesse suggests, it's a Functional Integration Testing (FIT) tool. Although some people use it as Unit Testing tool but it is totally an integration testing tool that helps developers and testers do the functional testing of their code when all the layers are integrated with each other. One can create test cases for User Acceptance Testing (UAT) or Functional Acceptance Testing (FAT) and then executed on the integrated environment.

This tool is very helpful when one or more teams are working on various layers, each doing the Unit Testing of their code, so you always need to test how the application is performing in the integrated environment, so this tool is best fitted to execute all the acceptance test cases and check if the application is performing well in an integrated environment.

You must be wondering as of now, can we do UI Automation testing, the answer is no, it is not a UI Automation tool but yes it can be integrated with various other tools like Selenium for the UI Automation testing.

This tool is standalone and only helps in testing the layer just below your UI, either the Façade or the Business Logic Layer.

As I said above, this tool can also be used by Quality Testers because one doesn't need to know any specific technology or language to create the test cases and execute them, it works on a very simple scripting that can also be done by testers by just spending a few hours learning the scripting concepts even without any knowledge of programming languages.

The best part I like is that without much effort, the technical leads can check if the server validations are all in place or not. In today's world we often say that validation should be both client-side and server-side (I will not say all the validations but yes many of them are required on both sides). With UI Automation tools you don't often end with checking your server-side validations but as in this tool you are directly interacting with your Business Logic so one can easily check these on server-side and can get the leakage fixed.
We will see how easy it is to test a sample class created by developers, by just using the Dashboard of Fitnesse.

So just before starting, we need Fitnesse on our machines if you don't have it then please follow the link and download it.

http://fitnesse.org/FitNesseDownload

Download "fitnesse-standalone.jar".

The scope of this article is to help you work with Fitnesse for .Net.

You also need to download the FitSharp that actually helps Fitnesse to run the methods in the library, so it basically acts as an engine that allows Fitnesse to execute the test cases or you can say the code and generate a required output page for the results.

There are two types of testing engines supported by Fitnesse.

  1. FIT: FIT is the test engine that helps invoke test cases, interprets Pages (Wiki Pages) and generates results. More than a testing engine, it is a testing framework in itself on which the Fitnesse is built upon. The only problem that was encountered by the developers or the code writer is that to make test fixtures they need to inherit their class with ColumnFixture class that in itself is a very heavy construct.
  2. SLIM: Because of the limitation of inheritance in FIT engine, there exists the Simple List Invocation Method (SLIM) engine. SLIM runs on a separate server that is ultimately invoked by the Fitnesse Server. The only responsibility of SLIM is to invoke the test cases or the methods. Now the developer can simply write their libraries as they want to without worrying about the inheritance model. Additionally it is very light-weight.

FitSharp can be downloaded from Github, follow the URL:

https://github.com/jediwhale/fitsharp/downloads

While doing the download, please check which .Net Framework version you want it to run with. Don't panic if you have multiple components of the application that are on different .Net Framework versions because you can make multiple hostings. In that case each is testing a specific component using the FitSharp DLL(s) of that version.

Now after downloading, just unzip the FitSharp package. Now copy down the following DLL(s) and EXE(s) at the same path where your JAR is present. Create a folder named FitSharp (I have created this folder so as to keep the directory structure neat and clean) at the same location where your JAR is and copy down the following DLL(s) and EXE(s) there.

  1. Runner.exe
  2. RunnerW.exe
  3. fitSharp.dll
  4. fit.dll

Now as soon as you do this you are done with all the components you require and we can proceed to the installation.

Installing Fitnesse

Before installing Fitnesse with the JAR file please ensure that Java is installed on your system.

Now for installing the Fitnesse, open the command Prompt with Administrator Permission. Run the following command:

Java –jar "<Path of your Fitnesse Jar file>" –p 8025

Please see the following screenshot for reference:

Integration-Testing-1.jpg

The following are the details of the command.

So what we are doing here is installing the JAR file using Java installed on our system. The path of the Jar file is the physical location where you have copied the JAR. In my case it is present in the "C" drive.

8025 is the port; as mentioned, by default the installation is done on Port 80, so if you have another web site or web application on Port 80 or you want to run Fitnesse on some other port of your choice then just provide the port as –p <PortNumber>.

Fitnesse is mow ready to be used, to check if it is running or not, enter the following URL:

http://localhost:<PortNumber>

In my example it is:

http://localhost:8025

And you will see it is running:

Integration-Testing-2.jpg

We are done with the installation of Fitnesse, now we need to configure Fitnesse to use the FitSharp testing engines, that can be very easily done from the dashboard only. Here in the following I will show you how you can configure both the FIT and SLIM engines and how to create test classes or fixtures for them. And then after that we will see how to create various test pages and write scripts to execute test cases by writing scripts or say creating Decision Tables (the term used in Fitnesse).

We will first look at FIT.

FIT Test Engine

For configuring FIT as the test engine for Fitnesse, open the Front Page of the Fitnesse as shown in the screenshot above. At the bottom of this page you will see an option "root". Click on this link and it will open a page for you as shown below:

Integration-Testing-3.jpg

Click on the Edit Button and write the following commands to configure the FIT Engine.

!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,FitSharp\fit.dll %p}
!define TEST_RUNNER {Fitsharp\Runner.exe}

All the paths mentioned above for the DLL(s) and EXE(s) are relative to the Jar file of the Fitnesse. Here we are using fit.dll that says that by default the FIT Engine will be used and in the preceding case we haven't specified any specific test engine that by default tells Fitnesse to use the FIT engine.

See the screenshot for the settings:

Integration-Testing-4.jpg

Now we are done with the Fitnesse test engine configuration with FIT, let's now look into how to create a Test Class for it.

For this open Visual Studio, create a class library project (the framework used should be the same as for which you have downloaded the FitSharp package). Add a reference of "fit.dll" to your project and add a class in it, refer to the following code for an example.

using fit;

namespace SampleLibrary

{

    public class UserTest : ColumnFixture

    {

        public string UserName { get; set; }

        public string Password { get; set; }

 

        public bool IsAuthenticated()

        {

            if (UserName == "Abhishek" && Password == "test")

            {

                return true;

            }

            else

            {

                return false;

            }

        }

    }

}

So here you can see that the Test class is being inherited by ColumnFixture.

Now SLIM

For configuring SLIM as the test engine for Fitnesse, open the Front Page of the Fitnesse as shown in the screenshot above. At the bottom of this page you will see an option "root". Click on this link and it will open a page for you as shown below:

Integration-Testing-5.jpg

Click on the Edit Button and provide the following commands to configure the FIT Engine.

!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,FitSharp\fitsharp.dll %p}
!define TEST_RUNNER {FitSharp\Runner.exe}

All the paths provided above for the DLL(s) and EXE(s) are relative to JAR file of the Fitnesse. Here we are using fitSharp.dll and SLIM is defined as the Test Engine.

See the following screenshot for the settings:

Integration-Testing-6.jpg

Now we are done with the Fitnesse test engine configuration with SLIM, let's now look into how to create a Test Class for it.

For this open Visual Studio, create a class library project (the framework used should be the same as the one you downloaded for the FitSharp package). Add a class in it, refer to the following code for an example.
 

namespace SampleLibrary

{

    public class UserTest

    {

        public string UserName { get; set; }

        public string Password { get; set; }

 

        public bool IsAuthenticated()

        {

            if (UserName == "Abhishek" && Password == "test")

            {

                return true;

            }

            else

            {

                return false;

            }

        }

    }

}

With this we are done with the configuration part, now let's see how to create Test Pages in Fitnesse, for this go to the Front Page and Edit that Page. Now add the name of the Page that you want to create in the end or in on the top or may be anywhere you want the reference of your test page as shown in the screenshot.

Integration-Testing-7.jpg

In the preceding screenshot you can see that I have created a new page named "UserTest". When you click on save you will see that there is something with your page name, and your page is not clickable, this shows that the page is new and now you can define your test on this page. In the example below I will show you how I will test the code in my UserTest class but before that we should understand what the relevance of adding a page is.

A Fitnesse Page can be any of a few types, in other words Static, Suite or a Test. One can do the settings by opening the page changing the properties from "Tools" -> "Properties"
as in the following:

  1. Test: This is the simple test page on which you will provide your script or will create Decision Tables to carry out test runs.
  2. Static: Static Pages are the pages on which we can't execute any test runs. So what's the use of this page, this page is useful for example in a scenario that the new library is being developed and by the time it is developed the Testing team can provide the scripts to test the library but they don't want the test run to be executed after they have created that page (yes, the test run is done by clicking "Test" on top of that page so you must be wondering why not a create a Test Page and not click on this button, but think of a scenario in which there is an automated system that runs the test cases so that system will not know that if the test run needs to be executed on this page or not, so we can make it Static; Fitnesse will decide that the test run needs not to be executed for this page).
  3. Suite: Suite is nothing but the group of Test pages, it basically is the way of keeping all the related Test Pages in one set and when we want a specific set of test cases to be executed we just run the test on the Suite instead of running test cases on each test page separately.

Now retuning back to creating a new page, now click on the"?" sign shown with your page name on the Front Page of Fitnesse. As soon as you will click on "?", your page will be opened. It's now time to provide some scripts on this page to run the test cases. Now we will see how to import your library that needs to be tested and how to create the Decision Table for executing the test cases. Although there are many scenarios that can exist with your test cases or your test cases need to cover, but it will not be possible to explain all of them. I will just be presenting you with a simple example and for other scenarios of yours you can click on the link "User Guide" on the Front Page.

As soon as you open your new page it will present you with a Rich Text Editor for the configuration of the test libraries and to create Decision Tables. For doing the configuration on this Page and to tell it the path of the test libraries (libraries that need to be tested, in my case it is Sample Library). So to make it easy and keep it separate from the development process, what we will do is create a Folder named "Projects" (This name can be of your choice) at the same path where the Fitnesse JAR file is present. Now build your project and copy the DLL(s) of your project into this folder. This is done to keep the things separate from the development process and also we can provide the relative path of this project's folder in the page configuration. (Relative paths are relative to the location of the JAR file.)

Add the following to your page to configure the path of the library and import a specific namespace in that library for which we will create the Decision Tables. This is also a Decision Table that we have created for the import, just to be very safe and to tell Fitnesse that the new Decision Table is getting started we add a "!" sign in the front of the first row of the table.

!path Projects\SampleLibrary.dll
!|import |
|SampleLibrary |

So here Path is the relative path of the DLL and the table row below the import row of the table tells the name of the namespace in that library. Now it's time to create a Decision Table for running your methods and see the expected results. See the code below for that:

!|UserTest |
|UserName|Password|IsAuthenticated?|
|"Abhishek"|"test"|true |
|"Abhishek"|"Jain"| true |

So what is done in the above Decision Table is that the first row tells the name of the class, the second row specifies the sequence of the parameters or the properties of that class in the library, the order in which we provide the inputs, since everything is separated by a Pipe ("|") in Fitnesse, the first parameter is Username and the second is the Password and the last one is the method that needs to be executed.

Integration-Testing-8.jpg

In the third row we created the first set according to our scenarios, in which we are defining the property values and the final is the expected result. And yes we are done with the first test case, now it's time to execute it by saving this on the Test page.

Integration-Testing-9.jpg

Now just click on the "Test" button to run the test cases and you can see the results. Just see the sample Result Page:

Integration-Testing-10.jpg

Now here you can see that the result both of my test cases is that they passed. With this I think I am done, please let me know in case something is missing or you need some more help on Fitnesse.

Up Next
    Ebook Download
    View all
    Learn
    View all