在visual studio 2010中使用specflow创建步骤定义文件,生成的特性文件不清晰

本文关键字:文件 清晰 定义 2010 studio visual 创建 specflow | 更新日期: 2023-09-27 18:17:05

c#新手。

安装规范流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

它与特征文件有一些相似之处,因为我可以看到引用的一些步骤,但是这里有很多噪音。我一直在youtube上看TheCamronBute的视频:

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

和在vid中生成的文件上面[不确定文件]没有行号引用,通常看起来更干净-直观地然后很容易将存根方法复制并粘贴到定义文件中,并创建测试。

从上面的文件清单中,~我不清楚该将清单的哪一部分复制到定义文件中。

当我将完整的清单复制到定义文件时,我得到了大量的复制错误。

有没有人遇到这个问题-我想知道如果是我的specflow版本,我绑定到1.3.3 ?

在visual studio 2010中使用specflow创建步骤定义文件,生成的特性文件不清晰

您正在查看的文件是在构建解决方案时由specflow创建的自动生成文件。不要在这个文件中放置任何代码。在右键单击项目文件时,可以使用添加新项选项来添加新的specflow步骤定义文件。在定义文件中添加您的特性文件步骤,specflow将找到这些步骤并针对您的特性文件运行它们。