Search code examples
c#.netspecflow

Specflow not recognizing steps


I have a specflow Feature file with the following When

When Request for servername 'someurl.com/szhm04c4.xml' is processed

When I press F12 Visual Studio tells me that I can copy the following Step-Definition:

[When(@"Request for servername '(.*)' is processed")]
public void WhenRequestForServernameIsProcessed(string p0)
{
    ScenarioContext.Current.Pending();
}

I paste this to my step-file which inherits from Steps and implement it

public void WhenRequestForServernameIsProcessed(string servername)
{
    var httpRequest = this.Bootstrapper.GetFake<IHttpRequest>();
    A.CallTo(() => httpRequest.Path).Returns(servername);

    var httpContext = this.Bootstrapper.Get<IHttpContext>();

    this.Bootstrapper.Get<IHostRequest>().Process(httpContext);
}

When I execute the test, it fials and I get following error message:

TechTalk.SpecFlow.SpecFlowException Test pending: No matching step definition found for one or more steps. using System; using TechTalk.SpecFlow;

namespace MyNamespace { [Binding] public class StepDefinitions { [When(@"Request for servername '(.*)' is processed")] public void WhenRequestForServernameIsProcessed(string p0) { ScenarioContext.Current.Pending(); } } }

Why is that? I did define this step...

Thanks in advance


Solution

  • You have to put the [Binding] Attribute to the class, so that SpecFlow can find your steps.