{"id":181311,"date":"2013-05-28T23:30:04","date_gmt":"2013-05-28T19:30:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=181311"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=181311","title":{"rendered":"<span class=\"post_title\">Data Driven Tests &#038; SpecFlow<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/www.specflow.org\/specflownew\/\">SpecFlow<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f Data Driven \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432. \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435:  <\/p>\n<ol>\n<li>\u0418\u043d\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0432\u0442\u043e-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 (\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API)<\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u043b\u0438\u043a\u043e, \u043b\u0443\u0447\u0448\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0433\u0434\u0435-\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e<\/li>\n<\/ol>\n<p>  \u041f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 Gesigner Generated \u043a\u043e\u0434\u0435 \u044f \u0441\u043c\u043e\u0433 \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0431\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DSL<\/h4>\n<p>  <\/p>\n<pre><code>[TestFixture] public class DslGenerationTestsBase : TestsBase {     private static ITestRunner _testRunner;      [TestFixtureSetUp]     public virtual void FeatureSetup()     {         _testRunner = TestRunnerManager.GetTestRunner();         var features = GetType().GetCustomAttributes(typeof (FeatureAttribute), false);         if (!features.Any())         {             throw new ConfigurationErrorsException(&quot;Feature Attribute is required&quot;);         }          var feature = (FeatureAttribute)features.Single();         var featureInfo = new FeatureInfo(             new System.Globalization.CultureInfo(&quot;en-US&quot;),             feature.Title,             feature.Story,             ProgrammingLanguage.CSharp, null);          _testRunner.OnFeatureStart(featureInfo);     }      [TestFixtureTearDown]     public virtual void FeatureTearDown()     {         _testRunner.OnFeatureEnd();         _testRunner = null;     }      [TearDown]     public virtual void TearDown()     {         _testRunner.OnScenarioEnd();     }      protected void ScenarioSetup(ScenarioInfo scenarioInfo)     {         _testRunner.OnScenarioStart(scenarioInfo);     }      protected void ScenarioCleanup()     {         _testRunner.CollectScenarioErrors();     }      protected void Given(string given, string keyword = &quot;Given &quot;)     {         _testRunner.Given(given, null, null, keyword);     }      protected void When(string when, string keyword = &quot;When &quot;)     {         _testRunner.When(when, null, null, keyword);     }      protected void Then(string then, string keyword = &quot;Then &quot;)     {         _testRunner.Then(then, null, null, keyword);     } } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0438\u0441\u0430\u0442\u044c Feature \u0432 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c NUnit. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b Feature \u043f\u043e\u043f\u0430\u043b\u0430 \u0432 \u043e\u0442\u0447\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DescriptionAttribute. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043d\u0430\u0448 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043e\u0442 \u043d\u0435\u0433\u043e.  <\/p>\n<pre><code>[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class FeatureAttribute : DescriptionAttribute {     public string Title { get; private set; }      public string Story { get; private set; }      public CultureInfo CultureInfo { get; private set; }      public FeatureAttribute(string title, string story):base(title)     {         Title = title;         Story = story;         CultureInfo = new CultureInfo(&quot;en-US&quot;);     }      public FeatureAttribute(string title, string story, CultureInfo cultureInfo)         : base(title)     {         Title = title;         Story = story;         CultureInfo = cultureInfo;     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u0442\u0435\u0441\u0442\u043e\u043c<\/h4>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e TestCase \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c TestCaseSource \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430.  <\/p>\n<pre><code>[Binding] [Feature(&quot;DslGeneration&quot;,    &quot;In order to avoid silly mistakes\\n&quot; +     &quot;As a math idiot\\n&quot; +     &quot;I want to be told the sum of two numbers&quot;)] [Category(&quot;Examples&quot;)] public class DataDrivenDslGenerationExample : DslGenerationTestsBase {     private decimal _a;      private decimal _b;      [TestCase(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;)]     [TestCase(&quot;2&quot;, &quot;3&quot;, &quot;5&quot;)]     public void CodeSomeTest_DslIsGenerated(string a, string b, string c)     {         var scenarioInfo = new ScenarioInfo(&quot;DslGeneration Outline&quot;, null);         ScenarioSetup(scenarioInfo);          Given(&quot;Calculator is on&quot;);         When(string.Format(&quot;User fill {0} and {1}&quot;, a, b));         Then(string.Format(&quot;{0} is returned&quot;, c));          ScenarioCleanup();     }      [Given(@&quot;Calculator is on&quot;)]     public void CalculatorIsOn()     {              }      [When(@&quot;User fill (.*) and (.*)&quot;)]     public void Fill(int a, int b)     {         _a = a;         _b = b;     }      [Then(@&quot;(.*) is returned&quot;)]     public void ResultReturned(int c)     {         var actual = _a + _b;         Assert.AreEqual(c, actual);     } } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u0448 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0431\u043e\u0440\u043a\u0435, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0435 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code>&lt;specFlow&gt;   &lt;stepAssemblies&gt;     &lt;stepAssembly assembly=&quot;...&quot; \/&gt;   &lt;\/stepAssemblies&gt;   &lt;!-- For additional details on SpecFlow configuration options see http:\/\/go.specflow.org\/doc-config --&gt; &lt;\/specFlow&gt; <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SpecFlow.exe \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u043e\u0442\u0447\u0435\u0442<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/99a\/0e7\/d69\/99a0e7d69214977b85eeb1644d26489a.png\"\/><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0432\u0442\u043e-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f API \u0438 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/181311\/\"> http:\/\/habrahabr.ru\/post\/181311\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/www.specflow.org\/specflownew\/\">SpecFlow<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f Data Driven \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432. \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435:  <\/p>\n<ol>\n<li>\u0418\u043d\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0432\u0442\u043e-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 (\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API)<\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u043b\u0438\u043a\u043e, \u043b\u0443\u0447\u0448\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0433\u0434\u0435-\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e<\/li>\n<\/ol>\n<p>  \u041f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 Gesigner Generated \u043a\u043e\u0434\u0435 \u044f \u0441\u043c\u043e\u0433 \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0431\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-181311","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181311"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181311\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}