{"id":28678,"date":"2019-05-08T00:00:00","date_gmt":"2019-05-07T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/dai-requisiti-al-testing-con-specflow\/"},"modified":"2021-05-20T19:17:52","modified_gmt":"2021-05-20T17:17:52","slug":"from-requirements-to-testing-with-specflow","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/","title":{"rendered":"From requirements to testing with SpecFlow"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"28667\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/attachment\/259aa6db-907a-40dd-b2d7-43686e925312-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"259aa6db-907a-40dd-b2d7-43686e925312\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=300%2C178&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-28667\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"introduzione\">Foreword<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">In past few months, I casually analyze the employment of frameworks and codes&nbsp;testing methods. In particular, I am using two code&nbsp;writing methods, which are intriguing me a lot: the TDD (Test Driven Development) and the BDD (Behaviour Driven Development). In this article, I will talk you about a framework called SpecFlow, which will help you to easily make BDD.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"specflow\">SpecFlow<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">SpecFlow is a testing framework supporting BDD. It allows to define tests based on the behavior that our&nbsp;<em>feature&nbsp;<\/em>should have , using a simple grammar through a language called&nbsp;<strong>Gherkin<\/strong>. To do so, it uses a file type with&nbsp;<strong>feature<\/strong>&nbsp;extension. Below you can find an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nFeature: Batmobile Weapons\n\u00a0\u00a0\u00a0\u00a0In order fight villains\n\u00a0\u00a0\u00a0\u00a0As Batman\n\u00a0\u00a0\u00a0\u00a0I want to fire weapons from Batmobile.\n\u00a0\nScenario: Fire Cannon successfully\n\u00a0\u00a0\u00a0\u00a0Given I see villain\n\u00a0\u00a0\u00a0\u00a0When I press fire cannon button\n\u00a0\u00a0\u00a0\u00a0Then Batmobile cannons fire\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the feature file, you need to describe first which would be the function of the feature to test, and then you can specify different scenarios (use case in given-when-then form) on whom you will test it. It\u2019s clear that this method to write tests allows you not only to test the written code, but also permits you to support with precision our feature\u2019s environment. Let\u2019s use SpecFlow with an instance within Visual Studio.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"installazione-e-setup\">Installation and setup<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The installation of SpecFlow consists of two steps: 1) install the extension to Visual Studio 2017 and 2) create a project and configure it to be used with SpecFlow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install the extension, we go in the Tools menu and select&nbsp;<em>Extensions and updates<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"658\" data-attachment-id=\"28670\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/attachment\/specflow_ide-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide.png?fit=953%2C658&amp;ssl=1\" data-orig-size=\"953,658\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Specflow_ide\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide.png?fit=300%2C207&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide.png?fit=953%2C658&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide.png?resize=953%2C658&#038;ssl=1\" alt=\"\" class=\"wp-image-28670\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide.png 953w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_ide-480x331.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 953px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can create a new project, a&nbsp;<em>MSTest Test Project&nbsp;<\/em>type<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"945\" height=\"660\" data-attachment-id=\"28672\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/attachment\/specflow_nuovo_progetto-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto.png?fit=945%2C660&amp;ssl=1\" data-orig-size=\"945,660\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Specflow_nuovo_progetto\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto.png?fit=300%2C210&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto.png?fit=945%2C660&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto.png?resize=945%2C660&#038;ssl=1\" alt=\"\" class=\"wp-image-28672\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto.png 945w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/Specflow_nuovo_progetto-480x335.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 945px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the project has been created, right click on solution and choose&nbsp;<em>manage NuGet package for the solution&nbsp;<\/em>and then we install following packages: 1) SpecFlow 2) SpecFlow.Tools.MsBuild.Generation 3) SpecRun.SpecFlow<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, we can now create our first feature file!<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"aggiungere-un-feature-file\">Add a feature file<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">We now need to add a feature file to our project, which defines the specific feature and includes test scenarios. It\u2019s very easy to add a feature file to the project: right click on the project, then \u201cadd\u201d and \u201cnew element\u201d. On the left, we find the choice to select SpecFlow templates: we choose&nbsp;<em>SpecFlow Feature File<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"659\" data-attachment-id=\"28674\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/attachment\/new_feature_file-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file.png?fit=953%2C659&amp;ssl=1\" data-orig-size=\"953,659\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"new_feature_file\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file.png?fit=300%2C207&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file.png?fit=953%2C659&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file.png?resize=953%2C659&#038;ssl=1\" alt=\"\" class=\"wp-image-28674\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file.png 953w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/new_feature_file-480x332.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 953px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have to define our features and scenarios: I take as example a case I create specifically to easily explain the procedure. Imagine a project, where you have to import some CSV files from an external source and suppose you need to verify if the imported data are congruent with the origin. This is the feature file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nFeature: Items\n\u00a0\u00a0\u00a0\u00a0Import files from external application\n\u00a0\nScenario: Import a valid Items file\n\u00a0\u00a0\u00a0\u00a0Given the following specific Items file\n\u00a0\u00a0\u00a0\u00a0&quot;&quot;&quot;\n\u00a0\u00a0\u00a0\u00a0ItemNo;CreatedOn;ModifiedOn;Disabled\n\u00a0\u00a0\u00a0\u00a010045112022051066;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051064;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051062;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051070;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051071;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051072;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051073;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051074;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a010045112022051075;&quot;4\/20\/2017 10:32 AM&quot;;&quot;4\/21\/2017 10:32 AM&quot;;No\n\u00a0\u00a0\u00a0\u00a0&quot;&quot;&quot;\n\u00a0\u00a0\u00a0\u00a0When the service is started\n\u00a0\u00a0\u00a0\u00a0Then the following records must be present in Items table\n\u00a0\u00a0\u00a0\u00a0| ItemNo\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | CreatedOn\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | ModifiedOn\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | Disabled | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051066 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051064 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051062 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051070 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051071 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051072 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051073 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051074 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | \n\u00a0\u00a0\u00a0\u00a0| 10045112022051075 | &#039;2017-04-20 10:32:00.000&#039; | &#039;2017-04-21 10:32:00.000&#039; | 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In this file, our feature&nbsp;<strong>Items<\/strong>&nbsp;only import&nbsp;input files from an external application. Our scenario, on the contrary, specifies&nbsp;that:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Given<\/strong>: when we have a set of input values with a specific structure within the CSV itself (<em>ItemNo;CreatedOn;ModifiedOn;Disabled<\/em>);<\/li><li><strong>When<\/strong>: we are waiting for the service to be started;<\/li><li><strong>Then<\/strong>: the values made explicit in the table&nbsp;<strong>Items<\/strong>&nbsp;whose correspond to those present on the original CSV file.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">It sounds good, but how can we now write the code that execute this test? It\u2019s easy: just right click inside the feature file and choose&nbsp;<em>Generating step definitions<\/em>, in the context menu. Now insert a name for the binding class we are going to create and then click on \u201cgenerate\u201d. SpecFlow creates a class with this structure:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;Binding]\npublic class ItemsSteps\n{\n\u00a0\u00a0\u00a0\u00a0&#x5B;Given(@&quot;the following specific Items file&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void GivenTheFollowingSpecificItemsFile(string multilineText)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ScenarioContext.Current.Pending();\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;When(@&quot;the service is started&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void WhenTheServiceIsStarted()\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ScenarioContext.Current.Pending();\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;Then(@&quot;the following records must be present in Items table&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void ThenTheFollowingRecordsMustBePresentInItemsTable(Table table)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ScenarioContext.Current.Pending();\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As we can see, every step in the feature file is now&nbsp;<em>bound<\/em>&nbsp;on a method, on which we must implement what we need for the test execution. We are ready for the first test execution! Draft our solution and in the menu select&nbsp;<strong>Test -&gt; Window -&gt; Explore Test<\/strong>, then click on&nbsp;<strong>Run all<\/strong>. If the test ends well, we find in the Test Explorer a green dot on all tests. Now we need to insert some code inside our Binding Class.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;Binding]\npublic class ItemsSteps\n{\n\u00a0\u00a0\u00a0\u00a0List&lt;string&gt; itemList = new List&lt;string&gt;();\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;Given(@&quot;the following specific Items file&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void GivenTheFollowingSpecificItemsFile(string multilineText)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0File.WriteAllText(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Path.Combine(@&quot;c:\\temp&quot;, $&quot;TEST_items.csv&quot;),\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0multilineText);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;When(@&quot;the service is started&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void WhenTheServiceIsStarted()\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MyService service = new MyService();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0service.Start();\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;Then(@&quot;the following records must be present in Items table&quot;)]\n\u00a0\u00a0\u00a0\u00a0public void ThenTheFollowingRecordsMustBePresentInItemsTable(Table table)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach(var item in table.Rows)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Assert.IsTrue(FakeDatabase.ItemTable.Any(i =&gt; i.ItemNo == item&#x5B;0]));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;AfterTestRun]\n\u00a0\u00a0\u00a0\u00a0public static void AfterTestRun()\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0File.Delete(@&quot;c:\\temp\\TEST_items.csv&quot;);\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Summarizing:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>we create our CSV in the&nbsp;<strong>GivenTheFollowingSpecificItemsFile<\/strong>&nbsp;method with the information contained in the feature file<\/li><li>we start our service in the&nbsp;<strong>WhenTheServiceIsStarted<\/strong>, which only read items in the CSV and save them somewhere<\/li><li>in the method&nbsp;<strong>ThenTheFollowingRecordsMustBePresentInItemsTable<\/strong>&nbsp;we control if the rows are congruent with the table in the feature file<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We added the method&nbsp;<strong>AfterTestRun&nbsp;<\/strong>to run the test&nbsp;<em>clean-up<\/em>&nbsp;and delete the CSV file that has been created during their execution. In following executions, we verify again that all tests would be run properly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I wish I succeed to transmit you my curiosity for this framework. You can find some example code at this&nbsp;<strong><a href=\"https:\/\/github.com\/francydev\/SpecFlowExample\" target=\"_blank\" rel=\"noreferrer noopener\">link<\/a><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you at next article!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>How to pass from requirements description to tests in .NET with BDD and SpecFlow<\/p>\n","protected":false},"author":196716246,"featured_media":28667,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false},"categories":[688637524],"tags":[688637411,688637447],"class_list":["post-28678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-testing-en","tag-tools-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>From requirements to testing with SpecFlow - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"From requirements to testing with SpecFlow - Blexin\" \/>\n<meta property=\"og:description\" content=\"How to pass from requirements description to tests in .NET with BDD and SpecFlow\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-07T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T17:17:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Francesco de Vicariis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francesco de Vicariis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\"},\"author\":{\"name\":\"Francesco de Vicariis\",\"@id\":\"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f\"},\"headline\":\"From requirements to testing with SpecFlow\",\"datePublished\":\"2019-05-07T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:17:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\"},\"wordCount\":772,\"image\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"Testing\",\"Tools\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\",\"url\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\",\"name\":\"From requirements to testing with SpecFlow - Blexin\",\"isPartOf\":{\"@id\":\"https:\/\/blexin.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2019-05-07T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:17:52+00:00\",\"author\":{\"@id\":\"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f\"},\"breadcrumb\":{\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blexin.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"From requirements to testing with SpecFlow\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blexin.com\/en\/#website\",\"url\":\"https:\/\/blexin.com\/en\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blexin.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f\",\"name\":\"Francesco de Vicariis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blexin.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b3a3164fd0b28d429cd427aafae38a687a41a250a2bccf4ab3b0744138afd64e?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b3a3164fd0b28d429cd427aafae38a687a41a250a2bccf4ab3b0744138afd64e?s=96&d=identicon&r=g\",\"caption\":\"Francesco de Vicariis\"},\"url\":\"https:\/\/blexin.com\/en\/author\/francesco-devicariisblexin-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"From requirements to testing with SpecFlow - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/","og_locale":"en_US","og_type":"article","og_title":"From requirements to testing with SpecFlow - Blexin","og_description":"How to pass from requirements description to tests in .NET with BDD and SpecFlow","og_url":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/","og_site_name":"Blexin","article_published_time":"2019-05-07T22:00:00+00:00","article_modified_time":"2021-05-20T17:17:52+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Francesco de Vicariis","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Francesco de Vicariis","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/"},"author":{"name":"Francesco de Vicariis","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f"},"headline":"From requirements to testing with SpecFlow","datePublished":"2019-05-07T22:00:00+00:00","dateModified":"2021-05-20T17:17:52+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/"},"wordCount":772,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","keywords":["Testing","Tools"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/","url":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/","name":"From requirements to testing with SpecFlow - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","datePublished":"2019-05-07T22:00:00+00:00","dateModified":"2021-05-20T17:17:52+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/from-requirements-to-testing-with-specflow\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"From requirements to testing with SpecFlow"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6f8514ed8b0d3be31369ca5436c4781f","name":"Francesco de Vicariis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b3a3164fd0b28d429cd427aafae38a687a41a250a2bccf4ab3b0744138afd64e?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b3a3164fd0b28d429cd427aafae38a687a41a250a2bccf4ab3b0744138afd64e?s=96&d=identicon&r=g","caption":"Francesco de Vicariis"},"url":"https:\/\/blexin.com\/en\/author\/francesco-devicariisblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/259aa6db-907a-40dd-b2d7-43686e925312.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7sy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716246"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28678"}],"version-history":[{"count":6,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28678\/revisions"}],"predecessor-version":[{"id":31991,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28678\/revisions\/31991"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/28667"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}