Codemash 2013 – Getting Started With SpecFlow( with some BDD and ATDD thrown in )

presenter James Bender, VP of Technology Improving Enterprises www.ImprovingEnterprises.com.

3:35  PM  1/10/2013 in Portia/Wisteria

James comes from a full on Agile shop, very into TDD.  Indicating testing very important for dynamic languages, like javascript!

Reviewed benefits of TDD: Quality, documentation in tests, more focused on what I’m doing since have to break down tasks into smaller tasks, reduces rust code.  Code doesn’t exist if no business test exists that uses it.  Less bugs.  Bugs won’t come back since test exists that proves its gone.

Behavior Driven Development(BDD)

Acceptance Test Driven Development(ATDD):   Get acceptance tests, write code to make them pass to implement.

Mentioned that he does not believe that there is right way to do this.  Just ignore people who say you should do it this way and do whatever works best for you.

Started doing actual BDD for Tic Tac Toe as excercise using SpecFlow as unit testing framework and taking a BDD approach.  Used nuGet to get Specflow using Nunit.  Create project called TicTacToe.Specs.  Need to go to SpecFlows website and install some software for processing BDD tests.

SpecFlow is basically a code generator that creates unit test code from SpecFlow Gerkin based Feature file.

Working With SpecFlow

  1. Add a Feature file.  This allows english language gerkin syntax driven tests.  Feature, Scenario, Given Then When syntax.  The feature file and gerkin syntax has no dependency on platform or language so can use it on any platform.  ( Can use Gerkin based Feature definition as your user story also if you want.  Then your user stories can become actual tests)
  2. Generate test files.   Specflow can goof up generating files, if this happens just use Run Custom Tool option to get it to regenerate.
  3. Create a step for each Gerkin statement.  Each Gerkin statement will become a unit test in generated tests.  Specflow wraps test attributes with its own Given and When attributes so abstracts from particular test framework.  Passing tests are marked ‘done’ when run tests in specFlow.

We as a group then went through the process of creating specFlow scenarios for the Feature GameWinner in a Tic Tac Toe game.  You can parameterize specFlow tests by using regular experssions.  This allows scenarios that are different only in value will be matched by steps that are defined with regular expressions.

In SpecFlow can write a given that visually defines  a table that then passes a Table to the unit test.  Table is collection of TableRows which are just keyvalue pairs where key is the table column name.

Quickly reviewed Mocking and Dependency Injection as concepts that underpin SpecFlow and BDD.

How do you get your management to buy into specFlow and TDD.  What do you tell them to convince them to do this.  Money and time.  They want to know how long will this take and how much will it cost.  Showed cost of fixing defect based on when it’s found chart.  Much more expensive to find defects later in process.  BDD and SpecFlow aid in finding bugs sooner and therefore save us money!  Showed a Defect Density and time to delivery chart.  Longer projects had much lower defect density, but not that much longer and had a lot fewer defects.  QA people should be aware this technology will not replace them but allow them to focus on things that only a human can do.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *