繁体   English   中英

Specflow 特征文件不使用步骤定义

[英]Specflow features file not using step definitions

我创建了 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()
    {
            
    }

}

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

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

您在步骤 class 上缺少[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()
    {
            
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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