BDD - Acceptance Test Driven Development

Acceptance Test Driven Development

What is BDD:

BDD is an agile software development technique that encourages collaboration between developers, QA, and non-technical or business participants in a software project. It's more about business specifications than about tests. You write a specification for a story and verify whether the specs work as expected. The main features of BDD development are outlined below:
  •  A testable story (it should be the smallest unit that fits in an iteration)
  • The title should describe an activity
  • The narrative should include a role, a feature, and a benefit
  • The scenario title should say what's different
  • The scenario should be described in terms of Givens, Events, and Outcomes
  • The givens should define all of, and no more than, the required context
  • The event should describe the feature 

Advantage of BDD: 

  1. The first advantage is that this domain language is usable/understandable by domain experts as well. Given that you explain the available grammar for a context to a domain expert, he/she should even be able to write their own scenarios.
  2.  The second one is a bit less obvious, and is why one requires the ubiquitous language in a true BDD engine: since behaviour almost never changes, you can simply replace complete parts of an application without having to rewrite your specs. Instead of fixing tests, you only need to fix your contexts.
  3. You never have to rewrite your specs, since the behavior does not change, it's only the implementation that does.
  4. Fixing context implementations is usually less work compared to rewriting tests since a test usually contains some/a lot of dependencies in comparison to a single sentence of context grammar (which typically handles only a single dependency).
  5. If you apply bdd-like practices to tdd (also known as Arrange/Act/Assert), you are missing out on a large part of BDD IMHO; it is like writing your apps using dependency injection, but without using a container: it works and it makes your code better, but you could make your life a lot easier if you would use a container. 

Essential tools for BDD(Acceptance Test Driven Development)

The following are the list of tools that will be using for this demonstration. Please set these tools up before proceeding or trying out. The download is self-contained will all the dependencies. But to get the code template for BDD, you have to install SpecFlow.
SpecFlow: SpecFlow is the framework that supports BDD style specifications for .NET. SpecFlow is open source and it uses the official Gherkin parser and provides integration to the .NET framework.
MsTest:We will be using for writing our unit tests.


Step 1:

Need to Install "SpecFlow" to VS2010 through [Tools -> Extensions and Updates]


Edit the App.config file and add the test frame work as MS Unit Test. And the SpecFlow DLL reference to the specific project.


Step 2:

Add SpecFlow Feature file to your project.

Step 3:

Write the scenarios and Generate the step definitions. It will create a new Steps file with unit test scenarios.


Step 4:

Steps files will be basically created with pending methods. Need to implement the When, Then, Given methods.

Step 5:

Here we can handle TestInitialize(), ClassInitialize() features through SpecFlow Hooks.
  

Step 6:

Use ScenarioContext to pass the arguments.

 

Step 7:

Run the unit test and make it green.


Advantage :

Here the advantage is whenever the business changes the unit tests will be created automatically and need to implemented.

                

Comments

Popular posts from this blog

Angular JS – Part 2

.Net Collections