2011-12-08 39 views
2

新手C#程序員。使用visual studio 2010中的specflow創建步驟定義文件,生成的功能文件不清晰

安裝規範流程1.3,也有安裝NUnit的,在我的測試項目中引用旁邊,在Visual Studio 2010

從我所做的研究我的應用程序的項目,它看起來好像定義文件,添加時,可以填充針對特徵文件自動生成的殘段方法。

通過這個我的意思是我創建specflow功能文件使用運行單元測試,生成一個非結論性的功能文件。

當我看着這個我得到如下:

// ------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by SpecFlow (http://www.specflow.org/). 
//  SpecFlow Version:1.3.3.0 
//  Runtime Version:4.0.30319.239 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
// ------------------------------------------------------------------------------ 
#region Designer generated code 
namespace AcceptanceTest 
{ 
    using TechTalk.SpecFlow; 


    [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")] 
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 
    [NUnit.Framework.TestFixtureAttribute()] 
    [NUnit.Framework.DescriptionAttribute("Login")] 
    public partial class LoginFeature 
    { 

     private static TechTalk.SpecFlow.ITestRunner testRunner; 

#line 1 "Login.feature" 
#line hidden 

     [NUnit.Framework.TestFixtureSetUpAttribute()] 
     public virtual void FeatureSetup() 
     { 
      testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 
      TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Login", "In order to login to the application\r\nAs a user\r\nI want to have my domain passwor" + 
        "d authenticated", ((string[])(null))); 
      testRunner.OnFeatureStart(featureInfo); 
     } 

     [NUnit.Framework.TestFixtureTearDownAttribute()] 
     public virtual void FeatureTearDown() 
     { 
      testRunner.OnFeatureEnd(); 
      testRunner = null; 
     } 

     public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 
     { 
      testRunner.OnScenarioStart(scenarioInfo); 
     } 

     [NUnit.Framework.TearDownAttribute()] 
     public virtual void ScenarioTearDown() 
     { 
      testRunner.OnScenarioEnd(); 
     } 

     [NUnit.Framework.TestAttribute()] 
     [NUnit.Framework.DescriptionAttribute("My login and password is authentic")] 
     [NUnit.Framework.CategoryAttribute("mytag")] 
     public virtual void MyLoginAndPasswordIsAuthentic() 
     { 
      TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("My login and password is authentic", new string[] { 
         "mytag"}); 
#line 7 
this.ScenarioSetup(scenarioInfo); 
#line 9 
testRunner.Given("I am a valid user"); 
#line hidden 
      TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { 
         "Field", 
         "Value"}); 
      table1.AddRow(new string[] { 
         "Name", 
         "a.w"}); 
      table1.AddRow(new string[] { 
         "Password", 
         "correctpassword"}); 
#line 10 
testRunner.When("I enter the following information", ((string)(null)), table1); 
#line 15 
testRunner.And("I click the \"Login\" button"); 
#line 16 
testRunner.Then("The main application window should launch"); 
#line hidden 
      testRunner.CollectScenarioErrors(); 
     } 

     [NUnit.Framework.TestAttribute()] 
     [NUnit.Framework.DescriptionAttribute("My login and password are not authentic")] 
     [NUnit.Framework.CategoryAttribute("mytag")] 
     public virtual void MyLoginAndPasswordAreNotAuthentic() 
     { 
      TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("My login and password are not authentic", new string[] { 
         "mytag"}); 
#line 20 
this.ScenarioSetup(scenarioInfo); 
#line 21 
testRunner.Given("I am not a valid user"); 
#line hidden 
      TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { 
         "Field", 
         "Value"}); 
      table2.AddRow(new string[] { 
         "Name", 
         "a.w"}); 
      table2.AddRow(new string[] { 
         "Password", 
         "password"}); 
#line 22 
testRunner.When("I enter the following information", ((string)(null)), table2); 
#line 26 
testRunner.And("I click the \"Login\" button"); 
#line 27 
testRunner.Then("The main application window should not launch"); 
#line hidden 
      testRunner.CollectScenarioErrors(); 
     } 
    } 
} 
#endregion 

它具有一些相似的特徵文件,因爲我可以看到一些引用的步驟,但有很多的噪音在這裏。我一直在尋找TheCamronBute YouTube視頻:

http://www.youtube.com/watch?v=Pptwj55P03s

並在VID上述[非決定性的文件]所生成的文件不具有的行號的引用,並且通常出現清潔器 - 直觀它 t是那麼很容易將存根方法複製並粘貼到定義文件中並創建測試。

從我上面的文件列表中,我不清楚該列表的哪一部分複製到定義文件中。

當我將完整列表複製到定義文件時,會出現重複錯誤。

其他人碰到這個問題 - 我想知道是否我的版本的specflow,我綁在1.3.3?

回答

6

您正在查看的文件是在構建解決方案時由specflow創建的自動生成的文件。不要在這個文件中放置任何代碼。右鍵單擊項目文件時,可以使用添加新項目選項添加新的specflow步驟定義文件。在定義文件中添加功能文件步驟,specflow將查找步驟並針對您的功能文件運行它們。

+2

Lee是正確的,您需要添加下一步。我推薦觀看Rob Conery在Tekpub上的BDD介紹http://tekpub.com/view/concepts/5 – bitsprint

+0

@bitsprint:鏈接已經死亡。 –

+0

Tekpub被Pluralsight收購。看起來你仍然可以在http://youtu.be/SVwBz-ZTliw看到原始視頻 – bitsprint

相關問題