Binding Business Requirements to .NET Code using SpecFlow & BDD framework


Behavior-driven development is an extension of test-driven development that makes use of a simple, domain-specific scripting language. These DSLs convert structured natural language statements into executable tests i.e Using Gherkin Language In SpecFlow. The result is a closer relationship to acceptance criteria for a given function and the tests used to validate that functionality. As such it is a natural extension of TDD testing in general.


BDD focuses on:

Where to start in the process
What to test and what not to test
How much to test in one go
What to call the tests
How to understand why a test fails


Why BDD?

BDD helps build the right thing. 
  • Traditionally there are many handoffs - Requirements, development, component testing, integration testing and finally customer usage.
  • BDD is a software development process based on test-driven development (TDD)

BDD documents what is actually built
  • Documentation reflects how the system actually behaves.
  • Documentation is up-to-date and accurate.
  • Good for long-term maintenance.
  • Good for communicating with other teams.



How BDD works?
  • Up front, Product Managers, developers, and QA define the behavior of the system collaboratively.
  • They write a specification.
  • The specification defines what Product Owners want, what developers build and what QA tests.
  • The specification is used as a target for implementation and a means to validate the product


Why not TDD?
  • Details are lost when translating from business requirements to traditional MSTest unit tests.
  • With many handoffs, it’s very easy to have a full set of tests and still build the wrong software.
  • MSTest functional tests are inaccessible to product stakeholders.



BDD Framework: xBehave

  • SpecFlow is xBehave-based 
  • SpecFlow (very similar to cucumber from the Ruby stack) is excellent in facilitating xBehave BDD tests as Acceptance Criteria. It does not, however, provide a good way to write behavioral tests on a unit level. There are a few other xBehave testing frameworks, but SpecFlow has gotten a lot of attraction.
  • xBehave Benefit: stakeholders can read and understand the tests


What is Specflow?

Use SpecFlow to define, manage and automatically execute human-readable acceptance tests in .NET projects. Writing easily understandable tests is a cornerstone of the BDD paradigm and also helps build up a living documentation of your system.

SpecFlow is open source and provided under a BSD license. As part of the Cucumber family, SpecFlow uses the official Gherkin parser and supports the .NET framework, Xamarin, and Mono.

SpecFlow integrates with Visual Studio but can be also used from the command line (e.g. on a build server). SpecFlow supports popular testing frameworks: MSTest, NUnit (2 and 3), xUnit 2 and MbUnit.


SpecFlow+ adds additional functionality to SpecFlow, such as Visual Studio Test Explorer integration, a dedicated test runner with advanced test execution options, execution reports (HTML, XML, JSON) and much more. 


SpecFlow - One-Time Setup
  1. Install Visual Studio Plugin
  2. nuget: Install-Package SpecFlow
  3. Add to app.config:   
  4.    

     


For additional details on SpecFlow configuration options see


SpecFlow Overview – Running Tests

  • Install Visual Studio Plugin:






IF you are getting started with Specflow, you can refer here
For Advanced topics of Specflow, refer here y BDD?

Comments