我有一个包含以下内容的specflow特征文件
When
When Request for servername 'someurl.com/szhm04c4.xml' is processed
当我按
F12
时,Visual Studio 告诉我可以复制以下步骤定义:
[When(@"Request for servername '(.*)' is processed")]
public void WhenRequestForServernameIsProcessed(string p0)
{
ScenarioContext.Current.Pending();
}
我将其粘贴到继承自
Steps
的步骤文件中并实现它
public void WhenRequestForServernameIsProcessed(string servername)
{
var httpRequest = this.Bootstrapper.GetFake<IHttpRequest>();
A.CallTo(() => httpRequest.Path).Returns(servername);
var httpContext = this.Bootstrapper.Get<IHttpContext>();
this.Bootstrapper.Get<IHostRequest>().Process(httpContext);
}
当我执行测试时,它失败了,我收到以下错误消息:
TechTalk.SpecFlow.SpecFlowException 测试待处理:没有匹配的步骤 找到一个或多个步骤的定义。使用系统;使用 TechTalk.SpecFlow;
命名空间 MyNamespace { [捆绑] 公共类步骤定义 { [When(@"对服务器名称'(.*)'的请求已处理")] public void WhenRequestForServernameIsProcessed(string p0) { ScenarioContext.Current.Pending(); } } }
这是为什么呢?我确实定义了这一步...
提前致谢
您必须将 [Binding] 属性添加到类中,以便 SpecFlow 可以找到您的步骤。
确保:
如果测试在单独的组件中进行:
并不是说您不能拥有多个同名的 [Binding] 类(即使是不同的命名空间),否则 Specflow 会感到困惑,并且可能找不到您的步骤。
确保在创建功能文件和步骤定义后构建项目。 当您构建它时,将创建一个 .cs 文件作为功能文件的一部分,并绑定到您的步骤定义