我有这种情况:
[Given(@"I select cell (.+)")]
[When(@"I select cell (.+)")]
[Then(@"I select cell (.+)")]
public void WhenIClickOnExcelCellX(string cell)
{
excelDriver.SelectCell(cell);
}
Run Code Online (Sandbox Code Playgroud)
是否有任何通配符属性可以匹配这三个关键字中的任何一个?我想写这样的东西,不要担心我是否提供了该属性的映射.
[Any(@"I select cell (.+)")]
public void WhenIClickOnExcelCellX(string cell)
{
excelDriver.SelectCell(cell);
}
Run Code Online (Sandbox Code Playgroud)
实际上我很确定没有,这是设计的.
花点时间考虑一下Given,When和Then步骤正在努力实现,我想是这样的:
所以最多你可能会认为如果你When I select cell x是一个相当轻量级的实现,你可以(但不一定应该)重用它Given I select cell x.
然而,你Then I select cell x真的无效,相反它应该是Then cell x should be selected,即
using Should;
[Then(@"cell (.+) should be selected")] //Regex might need changing
public void ThenCellXShouldBeSelected(string cell)
{
excelDriver.IsSelected(cell).ShouldBeTrue(); //Or whatever the call is
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
更新
查看https://github.com/techtalk/SpecFlow/blob/master/Runtime/Attributes.cs上的代码,可以看出有一个基类,StepDefinitionBaseAttribute但它是抽象的.