SpecFlow – Agile Testing with Visual Studio


Introduction

SpecFlow supports TDD (Test Driven Development) and BDD (Behavior Driven Development) concepts, and integrates very well with Visual Studio.

Installing SpecFlow

Installing SpecFlow is straightforward, simply go to the Visual Studio Gallery site, download the SpecFlow extension and then install it.

Creating a new SpecFlow project

Once SpecFlow is installed, follow these steps to create a new project as part of your solution:

Create a new Unit Test project in Visual Studio, and Add SpecFlow as reference using the menu options: Tools -> Library Package Manager -> Manage NuGet Packages for Solution.

Select Online, then search for SpecFlow. Now select and install it.

specflow_nuget_dialog

New feature files can either be added via Add New Item, or Add Existing Item. A corresponding #C file will be generated for each .feature file.

Edit the feature file, then (inside the edit window) open the context window (right-click inside the file). From the menu, select ‘Generate Step Definitions’

specflow_edit_context_menu

A dialog will be presented, from where step definition skeletons can be selected for automatic generation:

specflow_generate_step_definitions_dialog

The following will be added to each method in the step definition file, remove these whilst adding the actual code

ScenarioContext.Current.Pending();

specflow_pending_step_definition

Remember to add a reference (in the Project Explorer) to the existing project to be tested, this will be used when completing the step definition files.

Add the following to the newly created step definition file, also with references to the modules to be tested:

using System;
using TechTalk.SpecFlow;
using Microsoft.VisualStudio.TestTools.UnitTesting;

There are various scenario runners available, we’ve found that MSTest offers one of the better solutions. Change application config as follows:

 <specFlow>
<unitTestProvider name=”MsTest” />
</specFlow>

specflow_app_config_settings

Right-click on the project, and select ‘Run Scenarios’.

If all scenarios are completed successfully, this will be the resulting display:

specflow_scenarios_success

Pending or failed scenarios will be marked accordingly, and drill-down options are available to find the point of failure.

 Conclusion

It offers a very good solution for introducing BDD and agile testing to Visual Studio solutions.

Resources

SpecFlow – http://www.specflow.org/specflownew/

Visual Studio Gallery – http://go.specflow.org/vsgallery

Modify default SpecFlow templates – http://www.marcusoft.net/2011/02/customize-your-specflow-templates-and.html


BY: SOFTWARE DEVELOPER AT INFOWARE STUDIOS


Enhanced by Zemanta

Interesting Infoware Studios Bookmarks

0
  Related Posts