1
votes

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

2
Does your step in code have the When attribute on it?Matt Hogan-Jones
Does your binding class have the [Binding] Attribute on it?Andreas Willich
Thank you! The [Binding] Attribute was missing, you can add this as answer if you want then i'm gonna mark is as solved :-)xeraphim

2 Answers

4
votes

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

0
votes

Make sure that:

  • The step does exist (search for the step's description in the source files)
  • The step corresponds to a public method in a public class decorated with [Binding]
  • The parameters of the step's description, usage in feature, supporting C# function line up.
  • The steps attribute is ONE string. You can't concatenate e.g. a prefix or suffix.

If the test is in a separate assembly:

  • It has to be declared in a file at the root of that assembly (Specflow limitation).
  • That assembly has to be referenced in a tag of the feature file's assembly (see the doc).

Not that you cannot have multiple [Binding] classes with the same name (even if a different namespace) or specflow will be confused and may not find your steps.