c# - 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()
{
}
}
我尝试了此页面上的步骤,但它们没有任何区别。
如何获取功能文件以使用正确的步骤定义?
解决方案
您缺少[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()
{
}
}
推荐阅读
- node.js - 有一种方法可以在 MongoDB 中强制执行引用完整性
- android - 如何在 android studio 设备模拟器中模拟来自“不可用”的电话?
- sql - 如何访问大查询表中列内的数据数组的列名?
- java - java.lang.ExceptionInInitializerError 引起:com.fasterxml.jackson.databind.JsonMappingException:Jackson 版本太旧 2.5.1
- r - 根据总和选择列
- python - 批量更新的 Welford 方差/标准算法的公式是什么?
- google-apps-script - 在两个电子表格之间查找一行,然后查找包含第一行中的值的行
- java - 如何在 JFROG 上上传带有目录的 jar 文件?
- android - 使用 addImage() 和会话优化 ArCore Fragment 导航
- python - UnboundLocalError:分配前引用的局部变量“var”