是在一行中指定给定的所有参数,还是在单独的行中指定每个参数?即哪个更好?
分别为每个参数
Scenario: some random scenario
Given a menu with a menu width of 19
And quit text of "quit"
And Fruit options of
|Text|
|some text|
When ...
Then ...
或某一行上特定 Given 的所有参数
Scenario: Some scenario
Given a menu with quit text of "quit" and menu width of 19 and Fruit options of
|Text|
|Some text|
When ...
Then ...
这似乎(我希望我错了)对您如何编写绑定具有以下含义,并开始影响您编写类的方式,这是不应该的!即第一个选项(每个参数单独的AND)如果您的类具有在创建对象后逐个设置的公共属性,则绑定更容易编写......
private Menu _menu;
[Given(@"a menu of fruit options")]
public void GivenAMenuOfFruitOptions(Table table)
{
string[] fruitOptions = table.GetColumn("Fruit");
_menu = new Menu(fruitOptions,null);
}
[Given(@"a menu width of (.*)")]
public void GivenAMenuWidthOf(string width)
{
_menu.Width = int.Parse(width);
}
[Given(@"a Quite text of ""(.*)""")]
public void GivenAMenuWidthOf(string quitText)
{
_menu.QuitText = quitText;
}
而选项二(都在一行上)更容易拥有一个带有构造函数的对象,该构造函数将所有参数作为构造函数参数。
private Menu _menu;
[Given(@"a menu with quit text of ""(.*)"" and menu width of (\d+) and Fruit options of ")]
public void GivenAMenuOfFruitOptions(string quitText, int width, Table table)
{
string[] fruitOptions = table.GetColumn("Fruit");
_menu = new Menu(fruitOptions,width, quitText);
}
我觉得好像我遗漏了一些东西,因为 specflow 的实现不应该影响我编写的代码,而且我担心上面的 #1 会鼓励过度有状态的对象。我是一个功能性的无国籍瘾君子。
任何指针都将是最有帮助的。
提前发送,
干杯,艾伦