gpt4 book ai didi

c# - Specflow 无法识别步骤

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:49 24 4
gpt4 key购买 nike

我有一个 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 Test pending: No matching step definition found for one or more steps. using System; using TechTalk.SpecFlow;

namespace MyNamespace { [Binding] public class StepDefinitions { [When(@"Request for servername '(.*)' is processed")] public void WhenRequestForServernameIsProcessed(string p0) { ScenarioContext.Current.Pending(); } } }

这是为什么呢?我确实定义了这一步...

提前致谢

最佳答案

您必须将 [Binding] 属性放到类中,以便 SpecFlow 可以找到您的步骤。

关于c# - Specflow 无法识别步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44109408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com