我将SpecFlow步骤转换为依赖StepArgumentTransformation
,因此我不必处理多个原始参数,但可以使用由转换方法构建的单个复杂参数。
但是我了解到我无法从步骤中删除原始参数,因为这会导致“参数计数不匹配”异常。
[Given("(something (\d) (\d))")]
public void Step(Something something)
{
// Does not work (parameter count mismatch)
}
[Given("(something (\d) (\d))")]
public void Step(Something something, int x, int y)
{
// Works, but is slightly confusing due to unused parameters
}
[StepArgumentTransformation("something (\d) (\d)")]
public Something Transform(int x, int y)
{
var something = new Something(x, y);
return something;
}
如何摆脱步骤方法中的x
和y
参数?
答案 0 :(得分:0)
你必须调整绑定的正则表达式。
这是一个具体的例子:
[Given("the coordinates are '(.*)'")]
public void Step(Something something)
{
// Does not work (parameter count mismatch)
}
[StepArgumentTransformation("X:(\d)/Y:(\d)")]
public Something Transform(int x, int y)
{
var something = new Something(x, y);
return something;
}
Usage:
Scenario: coordinate system
Given the coordinates are 'X:1/Y:2'
Step Argument Transformation的文档在这里:http://specflow.org/documentation/Step-Argument-Conversions/