我执行了这样的步骤:
@When("I add an attribute named '(.+)' with unit '(.+)' to the item named '(.+)'")
public void addAttributeToAndItem(String attributeName, String unitName, String itemName){
.....
}
在我的黄瓜方案中,我想添加一个没有单位的属性,因此“单位名称”的值应为并且为空字符串。如何在“场景”步骤中指定此空字符串。
我尝试过这个:
Scenario: add attribute to an item
When I add an attribute named 'Color' with unit ' ' to the item named ' Car'
但是它不起作用。 “”始终似乎是一个值(一个空格),而不是一个空字符串。请有人可以帮我吗?
您可以将其更改为''
,但是由于(.+)
将至少匹配任何一个,因此使用''
将不匹配步骤。
尝试在步骤定义中使用(.*)
,它将与一个空字符串(即''
)匹配>
我不明白为什么您需要知道该单元是一个空字符串。如果遵循上述建议并输入''
,则(.+)
或(.*)
将捕获两个撇号。您可以添加以下断言行以确认: