bigblue_27
bigblue_27

Reputation: 31

Creating the step definition file using specflow in visual studio 2010, the generated feature file is not clear

Newbie C# programmer.

Installed spec flow 1.3 and also have nunit installed and referenced in my testing project next to my app project in visual studio 2010

From the research I have done, it looks as if the definition file, when added, can be filled with stubbed methods auto generated against the feature file.

By this I mean I create the specflow feature file using the run unit tests, an inconclusive feature file is generated.

When I look in this I get the following:

// ------------------------------------------------------------------------------
//  <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

It bears some resemblance to the feature file, in that i can see some of the steps referenced, but there is alot of noise in here. I have been looking at TheCamronBute video on youtube:

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

and in the vid the generated file above[the inconclusive file] does not have the line number references, and generally appears cleaner - intuitively it t is then easy to copy and paste the stub methods into the definition file and create the tests.

From my file listing above, ~I am not clear on which part of this listing to copy across to the definition file.

When I copy the complete listing across to the definition file, I get a load of duplication errors.

Anyone else come across this problem - I am wondering if is my version of specflow, I am tied to 1.3.3 ?

Upvotes: 2

Views: 4316

Answers (1)

Lee Grindon
Lee Grindon

Reputation: 2175

The file you are looking at is the auto generated file created by specflow when you build your solution. Do not place any code in this file. You can add a new specflow step definition file by using the add new item option when right clicking your project file. Add your feature file steps in the definition file and specflow will find the steps and run them against your feature file.

Upvotes: 6

Related Questions