xeraphim
xeraphim

Reputation: 4645

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

Upvotes: 2

Views: 8798

Answers (3)

Navya Anna James
Navya Anna James

Reputation: 1

Make sure you build the project after creating the feature file and step defs. When you build it, a .cs file will create as a part of your feature file and that Binds to your step definition

Upvotes: 0

Vincent67
Vincent67

Reputation: 11

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.

Upvotes: 0

Andreas Willich
Andreas Willich

Reputation: 5835

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

Upvotes: 8

Related Questions