首页 > 解决方案 > Specflow 特征文件不使用步骤定义

问题描述

我创建了 DotNetCore XUnit 测试项目,但无法让 Specflow 在其中工作。

我的功能文件在\proj\Features\SpecflowFeatureFile.feature,我的步骤定义在\proj\SpecflowFeatureSteps.cs. 当我运行我的测试时,我得到了这个错误:

错误消息:
TechTalk.SpecFlow.xUnit.SpecFlowPlugin.XUnitPendingStepException:测试未决:没有为一个或多个步骤找到匹配的步骤定义。使用系统;使用 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();
    }
} }

这是我的功能文件:

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

这是步骤定义:

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()
    {
            
    }

}

我尝试了页面上的步骤,但它们没有任何区别。

如何获取功能文件以使用正确的步骤定义?

标签: c#.net-corespecflow

解决方案


您缺少[Binding]步骤类的属性。

[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()
    {
            
    }

}

推荐阅读