SpecFlow supports TDD (Test Driven Development) and BDD (Behavior Driven Development) concepts, and integrates very well with Visual Studio.
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.
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’
A dialog will be presented, from where step definition skeletons can be selected for automatic generation:
The following will be added to each method in the step definition file, remove these whilst adding the actual code
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:
There are various scenario runners available, we’ve found that MSTest offers one of the better solutions. Change application config as follows:
<unitTestProvider name=”MsTest” />
Right-click on the project, and select ‘Run Scenarios’.
If all scenarios are completed successfully, this will be the resulting display:
Pending or failed scenarios will be marked accordingly, and drill-down options are available to find the point of failure.
It offers a very good solution for introducing BDD and agile testing to Visual Studio solutions.
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
Interesting Infoware Studios Bookmarks
- See my delicious