Skip to main content

Simple FitNesse tutorial

(Time spent for writing - 1:30 min)

In simple words, FitNesse is a testing framework that can be used to develop automated test cases. I had searched many posts but could not find a single tutorial that could help me get started with FitNesse. So writing it now...

BTW I am a java developer, so this tutorial is in pure java! I use windows XP and Java version is 1.5.0

To get started first download FitNesse from http://fitnesse.org/
I didnt like its 2 minute example, because that just showed what it does, doesnt really help me to start with development. They should have a real getting started tutorial there, I think.

I had downloaded fitnesse20070619.zip from downloads section

After downloading, install it by unzipping the all the files to a some location like c:\fitnesse

c:\fitnesse will then act as the root folder for you and all the classpaths will be relative to root folder

By default FitNesse will run on port 80. If you want another port you can edit the run.bat file in the root folder. Once done just double click the run.bat file and you will see server starting. I get the following console message when server starts.


C:\fitnesse>java -cp fitnesse.jar fitnesse.FitNesse
FitNesse (20070619) Started...
port: 80
root page: fitnesse.wiki.FileSystemPage at ./FitNesseRoot
logger: none
authenticator: fitnesse.authentication.PromiscuousAuthenticator
html page factory: fitnesse.html.HtmlPageFactory
page version expiration set to 14 days.


Open the web browser (I have IE-7) and go to http://localhost/ you sould now see the homepage (called as frontpage) of your local FitNesse application something like this

In case you used another port say 8081 then you need to specify it as http://localhost:8081/



Before we dive into writing code, its worth nothing one important point - FitNesse uses a markup language known as wiki markup language to display its pages. To check this, lets see the contents of the home page that we see. Infact we will have to modify it to get started so lets open the source file named "content.txt" in "C:\fitnesse\FitNesseRoot\FrontPage" (remember, C:\fitnesse is my root and you may have some other root folder)


My content.txt looks like this... yours should also be similar!


!img-l http://files/images/FitNesseLogoMedium.jpg
!1 Welcome to [[FitNesse][FitNesse.FitNesse]]!
!3 ''The fully integrated standalone acceptance testing framework and wiki.''

!c '''Table of Contents'''
!c [[A One-Minute Description][FitNesse.OneMinuteDescription]]''What is [[FitNesse][FitNesse.FitNesse]]? Start here.''
!c [[A Two-Minute Example][FitNesse.TwoMinuteExample]]''A brief example. Read this one next.''
!c [[User Guide][FitNesse.UserGuide]]''Answer the rest of your questions here.''
!c [[Acceptance Tests][FitNesse.SuiteAcceptanceTests]]''FitNesse's suite of Acceptance Tests''


As we see, the home page displays contents from this file. Now just add a line MyTestCase at the end of this file. It will look like this now


!img-l http://files/images/FitNesseLogoMedium.jpg
!1 Welcome to [[FitNesse][FitNesse.FitNesse]]!
!3 ''The fully integrated standalone acceptance testing framework and wiki.''

!c '''Table of Contents'''
!c [[A One-Minute Description][FitNesse.OneMinuteDescription]]''What is [[FitNesse][FitNesse.FitNesse]]? Start here.''
!c [[A Two-Minute Example][FitNesse.TwoMinuteExample]]''A brief example. Read this one next.''
!c [[User Guide][FitNesse.UserGuide]]''Answer the rest of your questions here.''
!c [[Acceptance Tests][FitNesse.SuiteAcceptanceTests]]''FitNesse's suite of Acceptance Tests''

MyTestCase


Once done, save the contents.txt and refresh the homepage of FitNesse. You will see that MyTestCase is written at the bottom of your home page. Kool! did you see that question mark after MyTestCase??? you see this because you wrote MyTestCase as a single word in CamelCase, and all camelcase words become hyperlinks in fitnesse. Now we can define what should be in the page that links to MyTestCase. To do so, click on the "?" mark and you will find a text area where you can write the testcase data.

Add the following lines in the edit text box:


!path fitnesse.jar
!path FitNesseRoot/files/examples/

!myFixtures.RightTriangle
abcright()
345true
6810true
359false
----


Make sure that there is no space after any line. You should see this after you press the save button. Before we start writing the fixture code in java, lets see what we have written above. The first line here is a classpath definition. This simply means that use fitnesse.jar from the root folder and second line says to use the class files defined in FitNesseRoot/files/examples/

the next line defines the class that will be executed for this testcase. It is myFixtures.RightTriangle here. This means that we plan to create a java class known as RightTriangle in myFixures package. and we will store this package in c:/fitnesse/FitNesseRoot/files/examples/ folder.

Lets create the class file now
1) open command prompt
2) go to directory c:/fitnesse/FitNesseRoot/files/examples/ OR FitNesseRoot/files/examples/ (if it some directory does not exist then you can create it!)
3) create directory "myFixtures"
4) create RightTriangle.java in "myFixtures" directory
5) Add the following code in RightTriangle.java


package myFixtures;
import fit.ColumnFixture;

public class RightTriangle extends ColumnFixture
{
public double a;
public double b;
public double c;
public boolean right()
{
return (a*a+b*b)==(c*c);
}
}


6) save the java file
7) in the command prompt go to FitNesseRoot/files/examples/
8) compile using following command:
javac -classpath ../../../fitnesse.jar myFixtures/RightTriangle.java
9) you should see the classfile in myFixtures directory

That's it, go back to the MyTestCase page and click on the test button on the left habd side. You should see the colors of last column changing indicating that the testcases pass or fail!

I have copied this example from FitNesse examples and made changes to get it running on my system. I hope that you find it useful.

Stay Fit!
Bhajan

Comments

Good Post for the starters !!! Good Explaination ...helped me

Popular posts from this blog

Hive

Hive What is Transactional Processing? * Small data * recent data * updates data * real time * narrow scope - single data source What is Analytical Processing? * Mostly batch * Mostly old data * Mostly long running * wide scope multiple data source to give a big picture ----------- RDBMS (mostly for transactional) * Single m/c with backup, structured data, usually one source Its hard to do analytics on RDBMS Big Data (mostly for analytical using data warehouse) * distributed data, semi/unstructured, auto replication with fault tolerance, usually different source and different format Not always... * hbase is special db that can be configured for transactional processing even if its on big data * qlikview can be used for analyitial processing even if its running on a single m/c --------- Whats a Data Warehouse? Technology that aggregates data  from one or more sources for analytical processing used by long running jobs, lagged data, large data, multi s...

Simple tutorial to create RESTful web services using SPRING, GRADLE & ECLIPSE

How to create RESTful web services using SPRING, GRADLE & ECLIPSE * First install Eclipse  i n your machine by referring to the official wiki  (I have installed an eclipse version called Kepler in my machine) * After installing Eclipse, open it and go to "eclipse market place" to add Gradle as seen in below screenshots: * Now create a new blank Gradle project in Eclipse *Now lets build the blank project using Gradle to ensure that everything is fine so far * Now change the build.gradle file to below as seen in http://spring.io/guides/gs/rest-service/ buildscript { repositories { maven { url "http://repo.spring.io/libs-release" } mavenLocal () mavenCentral () } dependencies { classpath ( "org.springframework.boot:spring-boot-gradle-plugin:1.1.4.RELEASE" ) } } apply plugin : 'java' apply plugin : 'eclipse' apply plugin : 'idea...