SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

New to SpecFlow and have a stepdefinition file question #983

Closed sgavathe closed 6 years ago

sgavathe commented 6 years ago

New to Spec Flow and have a setup feature and stepdefintion file question.

SpecFlow Version:

Used Test Runner

Version number:

Visual Studio Version

Are the latest Visual Studio updates installed?

.NET Framework:

Test Execution Method:

<SpecFlow> Section in app.config

 <specFlow> 
    <unitTestProvider name="NUnit" />
    <bindingCulture name="en-US" />
    <stepAssemblies>
      <stepAssembly assembly="Bindings" />
    </stepAssemblies>
  </specFlow>

Repro Project

Issue Description

I have been trying to get my very first project setup using the steps provided at http://specflow.org/getting-started/

The step definition skeleton file looks much different than the above link. Am I missing something?

Steps to Reproduce

I have included the packages as below,

After I created first sample Feature file and the sample generated step definition file looks whole lot different than the one shown here.

My File ->

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

    public virtual void ScenarioCleanup()
    {
        testRunner.CollectScenarioErrors();
    }

    [NUnit.Framework.TestAttribute()]
    [NUnit.Framework.DescriptionAttribute("Add two numbers")]
    [NUnit.Framework.CategoryAttribute("mytag")]
    public virtual void AddTwoNumbers()
    {
        TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", new string[] {
                    "mytag"});

line 7

this.ScenarioSetup(scenarioInfo);

line 8

testRunner.Given("I have entered 50 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");

line 9

testRunner.And("I have entered 70 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");

line 10

testRunner.When("I press add", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");

line 11

testRunner.Then("the result should be 120 on the screen", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");

line hidden

        this.ScenarioCleanup();
    }

Your File:->

using System; using TechTalk.SpecFlow; using Microsoft.VisualStudio.TestTools.UnitTesting; using Example;

namespace MyProject.Specs { [Binding] public class CalculatorSteps { private int result; private Calculator calculator = new Calculator();

    [Given(@"I have entered (.*) into the calculator")]
    public void GivenIHaveEnteredIntoTheCalculator(int number)
    {
        calculator.FirstNumber = number;
    }

    [Given(@"I have also entered (.*) into the calculator")]
    public void GivenIHaveAlsoEnteredIntoTheCalculator(int number)
    {
        calculator.SecondNumber = number;
    }

    [When(@"I press add")]
    public void WhenIPressAdd()
    {
        result = calculator.Add();
    }

    [Then(@"the result should be (.*) on the screen")]
    public void ThenTheResultShouldBeOnTheScreen(int expectedResult)
    {
        Assert.AreEqual(expectedResult, result);
    }
}

}

Stephen-Mc commented 6 years ago

It looks like you have set up the project to use NUnit rather than SpecFlow+ Runner. If this is your first time using SpecFlow, I'd recommend that you stick to the steps in the guide so you have understood the basic principles and worked through the whole process once. You can always switch the project over to NUnit later. Your first goal ought to be to get some tests running and understanding how everything is tied together. One step at a time :)

You do not need to license SpecFlow+ Runner to run the tests, although there is a short delay before executing the tests. While that might get tiresome after while, for this project it is unlikely to be a problem. You can always request a trial key if the delay irks you.

sgavathe commented 6 years ago

Thank you. I figured, it had to be with nUnit. I was unsure about the license needed for SpecFlow+ Runner. Thanks for clarifying.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.