FitNesseIt is an open-source automated framework created
for software testing
It is excellent tool for collaboration in software development enabling developers, testers and customers to collaborate by writing tests
FitNesse is based on Ward Cunningham's framework for Integration Test (FIT) now developed by Robert C Martin
FitNesse Getting Stared
Download fitnesse-standalone.jar from fitnesse.org
Starting Fitnesse is by executing the jar file:
java -jar fitnesse-standalone.jar -p 9090
Note: Doing first time will create directories
You can now access FitNesse on URL: localhost:9090
FitNesse Overview
WikiTestsSlimRunner
FixturesSystemUnder Test
Customer readableTests
FitNesse
Results
FitNesse Overview..
FitNesse works by executing Wiki pages which call custom written Fixtures
Fixtures act as a bridge between wiki pages and the System Under Test
Fixtures can be written many programming languages like java, Scala...
Tests And suitesFitNesse has Suite. It is a collection of Tests. When we execute one Suite all tests are run in a Suite.
For creating a TaxCalculationSuite, go to localhost:9090/TaxCalculationSuite.
FitNesse is smart enough to open a new Suite page. Save it by not adding any contents.
FitNesse Wiki Test
To create FitNesse wiki test, hover on add button and select “Test”
It will open a new test page. Provide TaxCalculationTest name for the Test for now, and save it.
FitNesse Wiki Test
Writing Wiki Test page is simple. We create wiki tables. Each row in a table is separated by a pipe character.
For example a table header of id, name and age is created like this|id|name|age|
FitNesse Wiki TestFor TaxCalculation test we want to calculate tax on annual salary.
Here is a simple rule of Tax. If annual income is more than 100,000 it is 15%, or else it is 10%.
The test in FitNesse Wiki must provide input to Fixture code in Scala and we must assert to compare output matched with actual results.
|the tax for annual income|200000|is|30000|
FitNesse Wiki Test|the tax for annual income|200000|is|30000| is a specification of intent from a Tester or customer. Now, we can build support around this.
For us developers, we need to specify jars, classes and Fixture class that we will be executing methods on.
For finding libraries and classes we use !path in FitNesse wiki.!define TEST_SYSTEM {slim}!path /Users/meetumaltiar/.sbt/boot/scala-2.9.1/lib/scala-library.jar!path ../lib/fitlibrary-20080812.jar
Add above content at top of the test page and save. You will notice proper classpath set.
FitNesse Wiki TestWe will have to load a specific class on which the methods will be executed.
If our Fixture scala class is TaxCalculationFixture in com.knoldus.fixture package. Then, we will have to write following in FitNesse Wiki
|import| |com.knoldus.fixture|
!|script | TaxCalculationFixture|
FitNesse Wiki TestWe need to write our test having assertions. We will use DoFixture semantics in our Wiki.
|import| |com.knoldus.fixture|
!|script | TaxCalculationFixture||the tax for annual income|200000|is|30000|
Above definition means that we have a method in scala class TaxCalculationFixture:
def theTaxForAnnualIncomeIs(annualIncome: Double, tax: Double): Boolean
FitNesse Wiki Test|import| |com.knoldus.fixture|
!|script | TaxCalculationFixture||the tax for annual income|200000|is|30000|
If we use DoFixture then each odd column is a part of a method and each even column is parameter to the method.
If method is written in camel case we can write method in FitNesse wiki like a DSL
Completed Wiki Test
!define TEST_SYSTEM {slim}!path /Users/meetumaltiar/.sbt/boot/scala-2.9.1/lib/scala-library.jar!path ../lib/fitlibrary-20080812.jar
|import| |com.knoldus.fixture|
!|script | TaxCalculationFixture||the tax for annual income|200000|is|30000||the tax for annual income|100000|is|10000|
Using DoFixture
To start with add a dependency of fitnesse and fitlibrary in your SBT project containing the fixture
libraryDependencies += "org.fitnesse" % "fitnesse" % "20121220"
libraryDependencies += "org.fitnesse" % "fitlibrary" % "20080812"
DoFixture
DoFixture is a Scala class extending DoFixture class in FitLibrary
DoFixture is a Fixture and acts as a bridge between wiki FitNesse tests and System under test
Each odd column in table in wiki corresponds to part of method definition.
Each even column has parameters we can pass in function defined in a DoFixture
TaxCalculationFixture
package com.knoldus.fixture
import fitlibrary.DoFixtureimport com.knoldus.tax.TaxCalculatorService
class TaxCalculationFixture extends DoFixture {
val taxCalculatorService = new TaxCalculatorService
def theTaxForAnnualIncomeIs(annualIncome: Double, tax: Double) = taxCalculatorService.getTaxForAnnualIncome(annualIncome) == tax}
TaxCalculatorService
package com.knoldus.tax
class TaxCalculatorService {
def getTaxForAnnualIncome(annualIncome: Double): Double = (annualIncome <= 100000.0) match { case true => annualIncome * 0.10 case false => annualIncome * 0.15 }}
Running Tests
We can execute an individual FitNesse wiki Test
We can execute all tests by running a Suite. Running a suite will run all tests in a Suite
We can organize Suites depending on behavioral design of our application.
Code is available on Knoldus Github:https://github.com/knoldus/ScalaFitnesse
Thanks!!