<commit_before>---
published: true
title: Your First Steps with SpecFlow
layout: post
tags: [SpecFlow, BDD, SpecificationByExample, FirstSteps]
---
In this post, I will walk you through the steps you need to take to get your first [SpecFlow](http://www.specflow.org/) scenario up and running.

## Visual Studio

You will need a version of Visual Studio that can load plug-ins. Most versions can, it is mainly the Express editions of older Visual Studio versions that are unable to do that. If you do not have Visual Studio yet, then your best bet is the free [Community Edition of Visual Studio 2015](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx).

## SpecFlow

Next you need to install the SpecFlow plug-in in Visual Studio.

1. Start Visual Studio if it is not already running.
2. In the `Tools` menu, click on `Extensions and Updates ...`.  
   ![Start Extensions Manager](/public/img/2016-02-09_StartExtentionsManager.png)
3. Expand the `Online` node on the left hand side, and click on the `Visual Studio Gallery` node.  
   ![Open the Visual Studio Gallery](/public/img/2016-02-09_OpenTheVisualStudioGallery.png)
4. Search for `SpecFlow` in the search box in the top right corner, then click on the `Download` button for SpecFlow's entry in the search results.  
   ![Search for the SpecFlow Plug-in](/public/img/2016-02-09_SearchForTheSpecFlowPlugin.png)
5. When the installer has finished downloading, click on the `Install` button in the `Download and Install` window. A web page will open with some advice on how to get started with SpecFlow. Feel free to read it or close it.
6. Click on the `Restart Now` button to finish the installation. Visual Studio will restart.

## Set up a Project

Now we will set up a Visual Studio solution and project, and add references to SpecFlow and to a unit-testing framework.

1. Start a new project by expanding the `File` menu, navigating to `New` and clicking on `Project ...`. Alternatively you can simply press `Ctrl+Shift+N`.
2. In the `New Project` window
    1. Expand the `Installed` node in the tree on the left hand side, then `Visual C#`, then `Windows`, then `Classic Desktop`.
    2. Click on the entry for `Class Library` in the list in the middle pane.
    3. Provide a name in the `Name` textbox near the bottom, for example `FirstStepsWithSpecFlow`.
    4. Click on the `OK` button in the bottom right corner.      
    ![Create New Project](/public/img/2016-02-09_CreateNewProject.png)
3. Visual Studio provides a class named `Class1`. Delete it by right-clicking its file in the Solution Explorer and clicking `Delete`. Click on the `OK` button to confirm.
4. Add a reference to SpecFlow and [nUnit](http://www.nunit.org/), a unit-testing framework:
    1. Right-click on the project (named `FirstStepsWithSpecFlow`) in Solution Explorer and click on `Manage NuGet Packages ...`.
    2. In the `NuGet Package Manager` window, click on `Browse` and search for `SpecFlow.NUnit`.
    3. Click on the entry for `SpecFlow.NUnit` in the result list
    4. Click on the `Install` button on the right hand side.  
    ![Add NuGet Packages](/public/img/2016-02-09_AddNuGetPackages.png)
    5. Close the `NuGet Package Manager` window.

## Add a Feature File

We will now add the first `.feature` file: that is the kind of file that contains the scenarios that describe the expected behavior of your software.

1. Right-click on the project (named `FirstStepsWithSpecFlow`) in Solution Explorer and click on `Add`, then on `New Item...`.
2. In the `Add New Item` window
    1. Expand the `Installed` node in the tree on the left hand side, then `Visual C#`.
    2. In the list in the middle pane, scroll until `SpecFlow Feature File` is visible. It should be near the top.
    3. Provide a name for the feature file near the bottom.
    4. Click on the `Add` button near the bottom right corner.     

![Add Feature File](/public/img/2016-02-AddFeatureFile.png)

The `.feature` opens, and you will see a sample scenario (`Add Two Numbers`). 

We can now execute the specification for the first time. In the `Test` menu, point to `Run` and then click on `All Tests`. Alternatively, you can press `Ctrl+R,A`. Open the `Test Explorer` tool window by opening the `Test` menu, pointing to `Windows` and clicking on `Test Explorer`. You will see a list with a node for the sample scenario.

![Test Explorer: First Run](/public/img/2016-02-09_TestExplorerFirstRun.png)

Note: if the `Test Explorer` is empty, you need to install the `NUnit3 Test Adapter 3.0` plug-in in the same way you installed the `SpecFlow` plug-in earlier.

Select the `Add Two Numbers` scenario. You will see that the test was not run because no matching step definition was found for one or more steps. We will now provide those step definitions. 

## Add a Step Definition File

Add a step definition file in much the same way as you added a `.feature` file, except that you select the `SpecFlow Step Definition` entry.

![Add Step Definitions](/public/img/2016-02-09_AddStepDefinitions.png)

Execute the specification again. The Test Explorer tool window now has a different message: one or more step definitions are not implemented yet. SpecFlow found our step definitions and used them, but of course there is nothing meaningful inside them yet.

![Test Explorer: Second Run](/public/img/2016-02-09_TestExplorerSecondRun.png)<commit_msg>Fix one more link<commit_after>---
published: true
title: Your First Steps with SpecFlow
layout: post
tags: [SpecFlow, BDD, SpecificationByExample, FirstSteps]
---
In this post, I will walk you through the steps you need to take to get your first [SpecFlow](http://www.specflow.org/) scenario up and running.

## Visual Studio

You will need a version of Visual Studio that can load plug-ins. Most versions can, it is mainly the Express editions of older Visual Studio versions that are unable to do that. If you do not have Visual Studio yet, then your best bet is the free [Community Edition of Visual Studio 2015](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx).

## SpecFlow

Next you need to install the SpecFlow plug-in in Visual Studio.

1. Start Visual Studio if it is not already running.
2. In the `Tools` menu, click on `Extensions and Updates ...`.  
   ![Start Extensions Manager](/public/img/2016-02-09_StartExtentionsManager.png)
3. Expand the `Online` node on the left hand side, and click on the `Visual Studio Gallery` node.  
   ![Open the Visual Studio Gallery](/public/img/2016-02-09_OpenTheVisualStudioGallery.png)
4. Search for `SpecFlow` in the search box in the top right corner, then click on the `Download` button for SpecFlow's entry in the search results.  
   ![Search for the SpecFlow Plug-in](/public/img/2016-02-09_SearchForTheSpecFlowPlugin.png)
5. When the installer has finished downloading, click on the `Install` button in the `Download and Install` window. A web page will open with some advice on how to get started with SpecFlow. Feel free to read it or close it.
6. Click on the `Restart Now` button to finish the installation. Visual Studio will restart.

## Set up a Project

Now we will set up a Visual Studio solution and project, and add references to SpecFlow and to a unit-testing framework.

1. Start a new project by expanding the `File` menu, navigating to `New` and clicking on `Project ...`. Alternatively you can simply press `Ctrl+Shift+N`.
2. In the `New Project` window
    1. Expand the `Installed` node in the tree on the left hand side, then `Visual C#`, then `Windows`, then `Classic Desktop`.
    2. Click on the entry for `Class Library` in the list in the middle pane.
    3. Provide a name in the `Name` textbox near the bottom, for example `FirstStepsWithSpecFlow`.
    4. Click on the `OK` button in the bottom right corner.      
    ![Create New Project](/public/img/2016-02-09_CreateNewProject.png)
3. Visual Studio provides a class named `Class1`. Delete it by right-clicking its file in the Solution Explorer and clicking `Delete`. Click on the `OK` button to confirm.
4. Add a reference to SpecFlow and [nUnit](http://www.nunit.org/), a unit-testing framework:
    1. Right-click on the project (named `FirstStepsWithSpecFlow`) in Solution Explorer and click on `Manage NuGet Packages ...`.
    2. In the `NuGet Package Manager` window, click on `Browse` and search for `SpecFlow.NUnit`.
    3. Click on the entry for `SpecFlow.NUnit` in the result list
    4. Click on the `Install` button on the right hand side.  
    ![Add NuGet Packages](/public/img/2016-02-09_AddNuGetPackages.png)
    5. Close the `NuGet Package Manager` window.

## Add a Feature File

We will now add the first `.feature` file: that is the kind of file that contains the scenarios that describe the expected behavior of your software.

1. Right-click on the project (named `FirstStepsWithSpecFlow`) in Solution Explorer and click on `Add`, then on `New Item...`.
2. In the `Add New Item` window
    1. Expand the `Installed` node in the tree on the left hand side, then `Visual C#`.
    2. In the list in the middle pane, scroll until `SpecFlow Feature File` is visible. It should be near the top.
    3. Provide a name for the feature file near the bottom.
    4. Click on the `Add` button near the bottom right corner.     

![Add Feature File](/public/img/2016-02-09_AddFeatureFile.png)

The `.feature` opens, and you will see a sample scenario (`Add Two Numbers`). 

We can now execute the specification for the first time. In the `Test` menu, point to `Run` and then click on `All Tests`. Alternatively, you can press `Ctrl+R,A`. Open the `Test Explorer` tool window by opening the `Test` menu, pointing to `Windows` and clicking on `Test Explorer`. You will see a list with a node for the sample scenario.

![Test Explorer: First Run](/public/img/2016-02-09_TestExplorerFirstRun.png)

Note: if the `Test Explorer` is empty, you need to install the `NUnit3 Test Adapter 3.0` plug-in in the same way you installed the `SpecFlow` plug-in earlier.

Select the `Add Two Numbers` scenario. You will see that the test was not run because no matching step definition was found for one or more steps. We will now provide those step definitions. 

## Add a Step Definition File

Add a step definition file in much the same way as you added a `.feature` file, except that you select the `SpecFlow Step Definition` entry.

![Add Step Definitions](/public/img/2016-02-09_AddStepDefinitions.png)

Execute the specification again. The Test Explorer tool window now has a different message: one or more step definitions are not implemented yet. SpecFlow found our step definitions and used them, but of course there is nothing meaningful inside them yet.

![Test Explorer: Second Run](/public/img/2016-02-09_TestExplorerSecondRun.png)
{'fraction_non_alphanumeric': 0.07889619409204555, 'fraction_numerical': 0.019261042689137885, 'mean_word_length': 3.927007299270073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2011111', 'n_tokens_mistral': 3127, 'n_tokens_neox': 2936, 'n_words': 1582}