不使用步骤定义的 Specflow 特征文件
Specflow features file not using step definitions
我创建了 DotNetCore XUnit 测试项目,但无法让 Specflow 在其中工作。
我的特征文件在 \proj\Features\SpecflowFeatureFile.feature
中,我的步骤定义在 \proj\SpecflowFeatureSteps.cs
中。当我 运行 我的测试我得到这个错误:
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();
}
} }
这是我的功能文件:
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()
{
}
}
我尝试了 this 页面上的步骤,但没有任何区别。
如何让功能文件使用正确的步骤定义?
您在步骤 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()
{
}
}
我创建了 DotNetCore XUnit 测试项目,但无法让 Specflow 在其中工作。
我的特征文件在 \proj\Features\SpecflowFeatureFile.feature
中,我的步骤定义在 \proj\SpecflowFeatureSteps.cs
中。当我 运行 我的测试我得到这个错误:
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(); } } }
这是我的功能文件:
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()
{
}
}
我尝试了 this 页面上的步骤,但没有任何区别。
如何让功能文件使用正确的步骤定义?
您在步骤 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()
{
}
}