FitNesse With Scala


Published on

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

FitNesse With Scala

  1. 1. FitNesse With Scala Meetu Maltiar Principal Consultant Email: Twitter:@meetumaltiar
  2. 2. FitNesseIt is an open-source automated framework created for software testingIt is excellent tool for collaboration in software development enabling developers, testers and customers to collaborate by writing testsFitNesse is based on Ward Cunninghams framework for Integration Test (FIT) now developed by Robert C Martin
  3. 3. FitNesse Getting StaredDownload fitnesse-standalone.jar from fitnesse.orgStarting Fitnesse is by executing the jar file:java -jar fitnesse-standalone.jar -p 9090Note: Doing first time will create directoriesYou can now access FitNesse on URL: localhost:9090
  4. 4. FitNesse Overview FitNesse Slim System Tests Wiki Fixtures Runner Under Test ResultsCustomer readableTests
  5. 5. FitNesse Overview..FitNesse works by executing Wiki pages whichcall custom written FixturesFixtures act as a bridge between wiki pagesand the System Under TestFixtures can be written many programminglanguages like java, Scala...
  6. 6. Tests And suitesFitNesse has Suite. It is a collection ofTests. When we execute one Suite all testsare run in a Suite.For creating a TaxCalculationSuite, go tolocalhost:9090/TaxCalculationSuite.FitNesse is smart enough to open a new Suitepage. Save it by not adding any contents.
  7. 7. FitNesse Wiki TestTo create FitNesse wiki test, hover onadd button and select “Test”It will open a new test page. ProvideTaxCalculationTest name for the Test fornow, and save it.
  8. 8. FitNesse Wiki TestWriting Wiki Test page is simple. Wecreate wiki tables. Each row in a tableis separated by a pipe character.For example a table header of id, nameand age is created like this|id|name|age|
  9. 9. FitNesse Wiki TestFor TaxCalculation test we want to calculatetax on annual salary.Here is a simple rule of Tax. If annualincome is more than 100,000 it is 15%, orelse it is 10%.The test in FitNesse Wiki must provide inputto Fixture code in Scala and we must assertto compare output matched with actualresults.|the tax for annual income|200000|is|30000|
  10. 10. FitNesse Wiki Test|the tax for annual income|200000|is|30000| is a specification of intentfrom a Tester or customer. Now, we can build support around this.For us developers, we need to specify jars, classes and Fixture classthat 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.jarAdd above content at top of the test page and save. You will noticeproper classpath set.
  11. 11. FitNesse Wiki TestWe will have to load a specific class on which themethods will be executed.If our Fixture scala class is TaxCalculationFixturein com.knoldus.fixture package. Then, we will have towrite following in FitNesse Wiki|import||com.knoldus.fixture|!|script | TaxCalculationFixture|
  12. 12. FitNesse Wiki TestWe need to write our test having assertions. Wewill 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 inscala class TaxCalculationFixture:def theTaxForAnnualIncomeIs(annualIncome:Double, tax: Double): Boolean
  13. 13. 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 isa part of a method and each even column isparameter to the method.If method is written in camel case we canwrite method in FitNesse wiki like a DSL
  14. 14. 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|
  15. 15. Using DoFixtureTo start with add a dependency offitnesse and fitlibrary in your SBTproject containing the fixturelibraryDependencies += "org.fitnesse" %"fitnesse" % "20121220"libraryDependencies += "org.fitnesse" %"fitlibrary" % "20080812"
  16. 16. DoFixtureDoFixture is a Scala class extending DoFixture classin FitLibraryDoFixture is a Fixture and acts as a bridge betweenwiki FitNesse tests and System under testEach odd column in table in wiki corresponds to partof method definition.Each even column has parameters we can pass infunction defined in a DoFixture
  17. 17. TaxCalculationFixturepackage com.knoldus.fixtureimport fitlibrary.DoFixtureimport TaxCalculationFixture extends DoFixture { val taxCalculatorService = new TaxCalculatorService def theTaxForAnnualIncomeIs(annualIncome: Double, tax:Double) =taxCalculatorService.getTaxForAnnualIncome(annualIncome) ==tax}
  18. 18. TaxCalculatorServicepackage com.knoldus.taxclass TaxCalculatorService { def getTaxForAnnualIncome(annualIncome: Double):Double = (annualIncome <= 100000.0) match { case true => annualIncome * 0.10 case false => annualIncome * 0.15 }}
  19. 19. Running TestsWe can execute an individual FitNesse wikiTestWe can execute all tests by running a Suite.Running a suite will run all tests in aSuiteWe can organize Suites depending onbehavioral design of our application.
  20. 20. Code is available on Knoldus Github: Thanks!!