FitNesse is an open-source automated framework for Integration, Acceptance Testing. It increases collaboration between developers, testers and customers. This presentation was presented at Knoldus Knolx session. We used Scala to write Fixtures and used simple example to explain it.
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Â
FitNesse With Scala
1. FitNesse With Scala
Meetu Maltiar
Principal Consultant
Email: meetu@knoldus.com
Twitter:@meetumaltiar
2. FitNesse
It 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
3. 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
4. FitNesse Overview
FitNesse
Slim System
Tests Wiki Fixtures
Runner Under Test
Results
Customer readable
Tests
5. 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...
6. Tests And suites
FitNesse 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.
7.
8.
9. 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.
10.
11.
12.
13. 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|
14. FitNesse Wiki Test
For 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|
15. 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.
16. FitNesse Wiki Test
We 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|
17. FitNesse Wiki Test
We 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
18. 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
19. 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|
20.
21.
22. 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"
23. 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
24. TaxCalculationFixture
package com.knoldus.fixture
import fitlibrary.DoFixture
import com.knoldus.tax.TaxCalculatorService
class TaxCalculationFixture extends DoFixture {
val taxCalculatorService = new TaxCalculatorService
def theTaxForAnnualIncomeIs(annualIncome: Double, tax:
Double) =
taxCalculatorService.getTaxForAnnualIncome(annualIncome) ==
tax
}
26. 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.
27.
28. Code is available on Knoldus Github:
https://github.com/knoldus/ScalaFitnesse
Thanks!!