简体   繁体   中英

Specflow features file not using step definitions

I created DotNetCore XUnit test project and am having trouble getting Specflow to work in it.

My feature file is in \proj\Features\SpecflowFeatureFile.feature and my step definitions are in \proj\SpecflowFeatureSteps.cs . When I run my tests I get this error:

Error Message:
TechTalk.SpecFlow.xUnit.SpecFlowPlugin.XUnitPendingStepException: Test pending: No matching step definition found for one or more steps. using System; using TechTalk.SpecFlow;

namespace MyNamespace { [Binding] public class StepDefinitions { private readonly ScenarioContext _scenarioContext;

 public StepDefinitions(ScenarioContext scenarioContext) { _scenarioContext = scenarioContext; } [Given(@"the deployment script has been installed")] public void GivenTheDeploymentScriptHasBeenInstalled() { _scenarioContext.Pending(); } [Given(@"the publisher has been installed")] public void GivenThePublisherHasBeenInstalled() { _scenarioContext.Pending(); } [When(@"the process status is checked")] public void WhenTheProcessStatusIsChecked() { _scenarioContext.Pending(); } [Then(@"the process should be running")] public void ThenTheProcessShouldBeRunning() { _scenarioContext.Pending(); } } }

This is my feature file:

Feature: MyFeature
    Integration test for Publisher

@mytag
Scenario: Check the publisher is running
    Given the deployment script has been installed
    And the publisher has been installed
    When the process status is checked
    Then the process should be running

and this is the steps definition:

class MyFeatureSteps
{
    [Given(@"the deployment script has been installed")]
    public void GivenTheDeploymentScriptHasBeenInstalled()
    {
        Repository.Clone("ssh://git@mystash.com/proj/deployment.git", @".\EnvSetup");
    }

    [Given(@"the publisher has been installed")]
    public void GivenThePublisherHasBeenInstalled()
    {
            
    }

    [When(@"the process status is checked")]
    public void WhenTheProcessStatusIsChecked()
    {
            
    }

    [Then(@"the process should be running")]
    public void ThenTheProcessShouldBeRunning()
    {
            
    }

}

I tried the steps on this page but they made no difference.

How can I get the features file to use the correct step difinitions?

You are missing the [Binding] Attribute on your step class.

[Binding]
class MyFeatureSteps
{
    [Given(@"the deployment script has been installed")]
    public void GivenTheDeploymentScriptHasBeenInstalled()
    {
        Repository.Clone("ssh://git@mystash.com/proj/deployment.git", @".\EnvSetup");
    }

    [Given(@"the publisher has been installed")]
    public void GivenThePublisherHasBeenInstalled()
    {
            
    }

    [When(@"the process status is checked")]
    public void WhenTheProcessStatusIsChecked()
    {
            
    }

    [Then(@"the process should be running")]
    public void ThenTheProcessShouldBeRunning()
    {
            
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM