C# TechTalk.SpecFlow.BindingException:';参数计数不匹配!绑定方法
我正在尝试为specflow编写一个StepArgumentTransformation 我有下面的小黄瓜C# TechTalk.SpecFlow.BindingException:';参数计数不匹配!绑定方法,c#,specflow,gherkin,C#,Specflow,Gherkin,我正在尝试为specflow编写一个StepArgumentTransformation 我有下面的小黄瓜 Scenario: Test Arguments Given user enter once as 2 我已经在步骤定义中写了这个 [StepArgumentTransformation] public int GetOnces(string onces, string times) { return 1 * int.Parse(times);
Scenario: Test Arguments
Given user enter once as 2
我已经在步骤定义中写了这个
[StepArgumentTransformation]
public int GetOnces(string onces, string times)
{
return 1 * int.Parse(times);
}
[Given(@"user enter (.*) as (.*)")]
public void GivenUserEnterOnce(int num)
{
Assert.Equal(2, num);
}
但是,GetOnces方法从未被调用,我得到了异常
TechTalk.SpecFlow.BindingException:'参数计数不匹配!绑定方法“givenUserOnce(Int32)”应具有2个参数
绑定应如下所示:
[StepArgumentTransformation("(.*) as (.*)")]
public int GetOnces(string onces, string times)
{
return 1 * int.Parse(times);
}
[Given(@"user enter (.*)")]
public void GivenUserEnterOnce(int num)
{
Assert.Equal(2, num);
}
如果要转换的参数不止一个,则必须在StepArgumentTransformation处指定正则表达式。您的实际步骤只有get的一个参数,因此正则表达式中只有一个参数是有效的
您可以在这里找到相关文档:对我来说,问题在于我忘记/删除了场景中的“Then”行