TechTalk.SpecFlow.BindingException: '参数计数不匹配!装订方式
TechTalk.SpecFlow.BindingException: 'Parameter count mismatch! The binding method
我正在尝试为 specflow 编写一个 StepArgumentTransformation。
我有以下小黄瓜
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: 'Parameter count mismatch! The binding method 'GivenUserEnterOnce(Int32)' should have 2 parameters
绑定应该是这样的:
[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 中指定正则表达式。你真正的步骤只有一个参数,所以正则表达式中只有一个参数有效。
您可以在此处找到相关文档:https://specflow.org/documentation/Step-Argument-Conversions/
对我来说,问题只是我 forgot/removed 我的场景中的 "Then" 行
我正在尝试为 specflow 编写一个 StepArgumentTransformation。
我有以下小黄瓜
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: 'Parameter count mismatch! The binding method 'GivenUserEnterOnce(Int32)' should have 2 parameters
绑定应该是这样的:
[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 中指定正则表达式。你真正的步骤只有一个参数,所以正则表达式中只有一个参数有效。
您可以在此处找到相关文档:https://specflow.org/documentation/Step-Argument-Conversions/
对我来说,问题只是我 forgot/removed 我的场景中的 "Then" 行