簡體   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