1 / 100

Implementing ATDD/BDD with FIT and FitNesse

Implementing ATDD/BDD with FIT and FitNesse. June 2008 Version 1.0. Implementing ATDD/BDD with FIT and FitNesse. Intros Mechanics Pairing Breaks. What is ATDD/BDD. ATDD = Acceptance Test Driven Development BDD = Behavior Driven Development

talisha
Download Presentation

Implementing ATDD/BDD with FIT and FitNesse

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Implementing ATDD/BDDwith FIT and FitNesse June 2008 Version 1.0

  2. Implementing ATDD/BDD with FIT and FitNesse • Intros • Mechanics • Pairing • Breaks

  3. What is ATDD/BDD • ATDD = Acceptance Test Driven Development • BDD = Behavior Driven Development These are tests that tell us what the customer or a user of the system expects, nothing more and nothing less. BDD aims to help focus development on the delivery of prioritized, verifiable business value by providing a common vocabulary (also referred to as a Ubiquitous Language) that spans the divide between Business and Technology. See: http://behaviour-driven.org/

  4. Historical Way of Doing Development and Testing

  5. Let’s Turn Things Around

  6. Test Driven Development (TDD)

  7. Rules of Test Driven Development • Don’t write production code without driving through the test • Don’t check in with broken tests

  8. Test Driven Development • Ensures the software works as expected • Some aspect of continuous testing • Helps teach you to build small, isolated (decoupled) classes • Some aspect of continuous design • Helps teach you to continuously adapt to changing requirements • Some aspects of continuous analysis/design

  9. Acceptance Test Driven Development (ATDD)

  10. Click Test Acceptance Test Driven Development Movie Test

  11. Click Test Acceptance Test Driven Development Movie Test

  12. Click Test Acceptance Test Driven Development Movie Test

  13. Click Test Acceptance Test Driven Development Movie Test

  14. Visible tracking of progress Become part of automated suite Visible test results for each build Acceptance Test Driven Development

  15. Testing Steps Quiz: What are the steps within a single test? • Setup test data (Given) • Perform action to be tested (When) • Verify results (Then) • Clean-up

  16. (Given) Setup test data Testing Steps Movie Test (When) Perform action to be tested (Then) Verify results

  17. Overview: FIT vs. FitNesse • FitNesse: • FitNesse builds on FIT • Web-based front-end for creating, managing, and running FIT test • Webserver – Test are easily accessible to anyone • Tests are Wiki pages • Helps organize tests into suites • Open source:http://fitnesse.org/ • Micah Martin is the primary author and architect of FitNesse. Robert Martin is the number 2 man. FIT: “Framework for Integrated Testing” • core framework for testing • Command-line tool: easily scriptable • Tests are Word or Excel documents saved as HTML • Available for various languages (not just Java) • Has become a standard in agile space • Open source: http://fit.c2.com/ • Invented by Ward Cunningham • OO Patterns • CRC Cards • WikiWikiWeb • eXtreme Programming • FIT

  18. The Need for FIT & FitNesse? • They are tools for enhancing collaboration in software development. • They communicate with clear, concrete examples • They allow customers, testers, and programmers to learn what their software should do and what it does do. • They provide a tight integration between the production code and test allowing those test to be automatically run every time code is checked in. • They make it easy for everyone, technical and non-technical, to understand and maintain tests • Tests can be written before the code is - by testers and trained agile customers • They provide a powerful lightweight, open-source framework to test almost anything the business cares about

  19. What does FIT test? Whatever you want • Business rules • Workflows • UI • Integration

  20. Running a FIT Test • Can be automated into your current build • Using ant targets & cruisecontrol • Can be run from your IDE • Can be run from command-line

  21. What Platforms are Support for Fit? • Java • .Net • Python • Perl • Smalltalk • C++ • Ruby

  22. FIT Architecture

  23. Setup – Required Libraries Add the following libraries to the path. Dependent jars can be found in the repositories as well. • Fit - http://fit.c2.com/wiki.cgi?DownloadNow • fit-eg.jar • fit.jar • fitplugin-yyyyddmm.jar • FitLibrary - http://apdcodehaus.dev.sabre.com/svn/tools/fitlibrary • fitlibrary.jar • FitNesses - http://apdcodehaus.dev.sabre.com/svn/tools/fitnesse • fitnesse.jar

  24. Required Folders For FitNesse Server • FitNesseRoot - This is where your tests will go. http://apdcodehaus.dev.sabre.com/svn/tools/fitnesse • Under this directory are directories for FitLibrary and FitNesse • You should create a new directory for project specific suite(s) of test

  25. Starting the FitNesse Server The fitnesse server is a java application. • Server Class - fitnesse.FitNesse • Program parameters - –e 0 • –e 0 – number of days before page version expires • See http://fitnesse.org/FitNesse.StartingAndStoppingFitNesse for more options • Working directory should point to the directory containing the FitNesseeRoot directory • Class path should contain fitnesse.jar

  26. Running FitNesse test from IntelliJ The test runner for fitnesse is a java application. • Class - fitnesse.runner.TestRunner • Program parameters - -v localhost 80 PointOfSale.BaseFitFixtures • -v verbose • localhost – server where fitnesse server is running • 80 – port fitnesse server is running on • PointOfSale.BaseFitFixtures – test or suite to run • See http://fitnesse.org/FitNesse.CommandLineTestRunner for more options • Working directory –directory containing the FitNesseRoot directory

  27. Running FitNesse Test from a Browser Assumes server was started on the localhost on port 80 • http://localhost/PointOfSale • localhost - the server and port where the server is running. The default port is 80 • PointOfSale – the page to start with.

  28. How to Debug FitNesse Test/Fixture from IntelliJ • Class - fitnesse.runner.TestRunner • Program Parameters - -html stdout -debug -v localhost 80 PointOfSale.BaseFitFixtures.TestAsapShipping • -html stdout – format results as HTML and print to standard out • -debug - prints FitnesseServer protocol actions to stdout • -v localhost 80 PointOfSale.FitLibrary.TestAddItemToCatalog – same as running test with out debugging • See http://fitnesse.org/FitNesse.CommandLineTestRunner for more options • Working directory - directory containing the FitNesseRoot directory

  29. How to Debug FitLibrary Test/Fixture from IntelliJ • Class - fitlibrary.suite.TestRunner • Program Parameters - -html stdout -debug -v localhost 80 PointOfSale.FitLibrary.BusinessLogicSuite.ApplicationTests.TestAsapShipping • -html stdout – format results as HTML and print to standard out • -debug - prints FitnesseServer protocol actions to stdout • -v localhost 80 PointOfSale.FitLibrary.BusinessLogicSuite.TestAsapShipping – same as running test with out debugging • See http://localhost/FitLibrary.UserGuide.BatchWithFitNesse for more options • Need fitlibrary.jar file in path • Working directory - directory containing the FitNesseRoot directory

  30. Exercise - FitNesse Setup In this exercise we will setup and run the FitNesse server. Part 1: • Run IntelliJ and open the FitAndFitnesseSample project • Setup the Fitnesse server as an application in IntelliJ • Start the server and verify it is running by going to http://localhost/PointOfSale Part 2: • Verify the tests run and pass Extra Credit:  • Setup IntelliJ to debug a FitNesse test and FitLibrary test

  31. Creating FitNesse Pages FitNesse is a wiki web server. Every FitNesse page has a name in so-called camel-case format, in which the first letter is upper-case, and at least one other letter in the word is upper-case. The name of this page, EditingFitNessePages, is an example. This convention makes it truly easy to create new pages and links to those pages. When you edit an existing page and insert a new camel-case word, such as ThisHereNewPage?, and then click the Save button, FitNesse interprets that to be a link to a new, as-yet-uncreated page. It indicates this to you by putting a question mark at the end of the name. If you then click on that question mark, FitNesse displays an edit frame, enabling you to put something on that new page. If you type anything at all in there and click Save, your new page is created, and the link to it is enabled on the originating page. See http://fitnesse.org/FitNesse.EditingFitNessePages

  32. Editing FitNesse Pages Once you are on a page your want to change, hit the Edit button in the upper left. (If the button does not appear, then the page is not edit-enabled.)A new window will pop up with an edit frame containing the markup language of the current page. You specify formatting using a simple markup language. Simply make your changes to the page and hit the Save button. Voila! Your changes appear on the page. See http://fitnesse.org/FitNesse.EditingFitNessePages

  33. Page Properties FitNesse pages can have attributes that alter the way the pages are displayed, and how they behave. These can be enabled or disabled for a page by hitting the Properties button. • Edit: When set, this property causes the Edit button to be displayed • Search: This property enables or disables the Search button. • Test: This property instructs FitNesse to treat the page as a fitnesse test page • Suite: Pages with this property are test suites. All sub pages are considered part of the suite. Any sub page with the Test property set is considered a test within the suite. • Versions: Enables the Versions button. • Properties: Enables the Properties button.

  34. Table 1 Table 3 Plain English Tables Table 2 Java, .Net, etc. Fixture 2 Fixture 1 System Under Test How does FIT work? • Agile Customer define and organize tests • Development team implements fixture layer • Everyone runs the tests

  35. public class Division extends ColumnFixture { public double numerator,denominator; public double quotient() { return numerator/denominator; } } How Fit works (in a Nutshell) • Fit works by reading tables stored in HTML files (wiki pages for fitnesse) that customers, testers, business analysis, etc. write. • Each table is interpreted by a “fixture” that developers write. • Fixtures test the production code by using the input data and expected output data provided in the tables. • The fixture carries out the tests, coloring the reported table (Red, Green, Yellow) so that you can tell which tests passed and which failed.

  36. Basic FitNesse Syntax – What Fixture am I using • At the top of a test page you can define a fixture to use in the test. !|com.sabre.apd.fixture.ClearOrdersFixture| • The first row of a table can also define what fixture the test table uses. • !|com.sabre.apd.fixture.SetupCatalogFixture| • |name|catalogId|description|price|success()| • |Widget|1|Does the work|20|true| • |Gadget|2|Made up of widgets|100|true| See http://fitnesse.org/FitNesse.MarkupFixture

  37. Comments in Test Pages • You can add a comment to the wiki markup text by simply putting the '#' sign as the first character of a line. The entire line, including the line end, will be ignored. # This is a comment • A note is created using the !note widget as follows • !note this is a note. The resulting text will be rendered in a small, gray, centered font. See: http://fitnesse.org/FitNesse.MarkupComments http://fitnesse.org/FitNesse.SuiteAcceptanceTests.SuiteWidgetTests.TestNote

  38. Formatting Text • Italics - enclose the section of text in two single quotes • Bold - enclose the section of text in three single quotes • Strike through - surround the text with two dashes • Horizontal rule - four or more dashes. The more dashes, the thicker the line There are many more options see: http://fitnesse.org/FitNesse.MarkupLanguageReference

  39. Test Table - Column Tests A column test table is created with the following syntax: |eg.Division| |numerator|denominator|quotient?| |10|2|5| |12.6|3|4.2| The top row of the table provides the name of the FixtureCode that Fit will use to process the table. The second row specifies the inputs and outputs of the fixture; the column headings numerator and denominator specify columns of input values, and the quotient? heading specifies a column of expected return values. So if we divide 10 by 2, we expect to get back 5. See http://fitnesse.org/FitNesse.ColumnFixture

  40. Test Tables – Row Tests This style of test table is best for checking the results of queries. |fitnesse.fixtures.PrimeNumberRowFixture | |prime| |2| |3| |5| This test table style does not read the way that a ColumnFixture style test table does. In this case, each cell in the prime column represents a key that identifies one of the records we expect to get back (in this case, a prime number). And the entire set of rows of data represent the output we expect to get back: no more and no less than that exact set of records (though they need not be in that exact order). See http://fitnesse.org/FitNesse.RowFixture

  41. Test Tables – Action Tables Action Tables are for testing sequences of events |Action Fixture| |start|fitnesse.fixtures.CountFixture | |check|counter|0| |press|count| |check|count|1| |enter|counter|5| |check|count|5| See http://fitnesse.org/FitNesse.ActionFixture

  42. Test Tables – Comment Table Sometimes you just want to explain something using a table. You don't want it to be a test table |Comment| |This is just a comment| |and will not participate| |in the tests on this page.| See http://fitnesse.org/FitNesse.CommentTables

  43. Exercise – Create a Classic FitNesse Test page In this exercise we will create a test page using a Column and Row Fixture • Create a new test page TestAddItemToCatalog in the suite http://localhost/PointOfSale.BaseFitFixtures • Use the com.sabre.apd.fixture.SetupCatalogFixture Fixture to add items to the catalog • Use com.sabre.apd.fixture.ViewCatalogFixture to verify the items exists in the catalog

  44. Domain/Work Flow Syntax What if you did not need a fixture but the test could talk directly to production code? This is the idea behind the Domain/Work Flow Syntax. • Focus on a single work flow in the application • Work flows think of what the user wants to do not how the business logic or the GUI is implemented • No fixture is needed but maybe a small adaptor for different levels in the application • Test should run against any level of the application

  45. Domain/Work Flow Syntax - Benefits Benefits of Work Flow Syntax • Less Fixture Code • Less Test Duplication • Better Reuse of Tests • Fewer test to change when requirements change • All levels of application are tested equally

  46. Domain/Work Flow Syntax – Example Test Simple Example of Work Flow Test ---- !|fitlibrary.eg.Calculator| * Let's start with a ''total'' value of 10 already in the calculator |''total''|10| ---- * Now we carry out an action: add 5 |+|5| ---- * We expect that the ''total'' will now be 15 |''total''|15| http://localhost/FitLibrary.UserGuide.FitLibraryByExample.CalculatorWorkflow.CalcuLator

  47. Domain/Work Flow Syntax – rendered by FitNesse

  48. Domain/Work Flow Syntax – Tests All Levels of Code How Do I make a test work at different levels of code? • This is done with a DomainAdapter that defines the context I am testing in. • The DomainAdapter should be part of the setup for a suite instead of inside test. public class CalculatorAdapter extends DomainAdapterWithVariables { private Object systemUnderTest; public CalculatorAdapter { systemUnderTest = new Calculator(); } } http://localhost/FitLibrary.GlosSary.DomainAdapter

  49. Domain/Work Flow Syntax – Reject We specify that an action is to be rejected (a sad path), with the special action reject in the first cell: |reject|add product|Item1|with id|1|to catalog| This table will call a method on the domain adapter or the system under test with the name addProductWithIdToCatalog(param1, param2) passing the values “Item1” and “1” as parameters to the method. This test will pass if an Exception is thrown or a boolean false is returned. http://localhost/FitLibrary.UserGuide.FitLibraryByExample.WorkFlow.WhenActionsFail

  50. Domain/Work Flow Syntax – Row tests Some special actions apply to the rest of their row: • check - checks whether the result of the action in the rest of the row matches the value in the last cell of the row. That last cell is colored green, red, etc accordingly. • not - acts the same as reject • ensure -checks that the action in the rest of the row succeeds • show -displays the result of the action in the rest of the row by adding an extra cell in the report • show dot -displays the result of the action in the rest of the row by adding an extra cell in the report. This is shown as a Dot graph • Note - ignores the rest of the row, allowing notes to be included in tables http://localhost/FitLibrary.UserGuide.FitLibraryByExample.WorkFlow.WorkflowSummary

More Related