IntelliJ要求在不同的Cucumber步骤之间选择声明

问题描述 投票:2回答:2

我有两个相似的步骤,但措辞不完全相同。但是,IntelliJ不断要求我在它们之间进行选择,就像它们是重复的一样,不知道为什么吗?

enter image description here

@And("^I add \"([^\"]*)\" as the history|comment|details for the item$")
public void iAddAsTheHistoryForTheItem(String text) {
    addComment(text);
}


@Then("^I am able to add a history|comment|details to the item$")
public void iAmAbleToAddAHistoryToTheItem() {
    addHistory();
    assertFalse(isHistoryClean());
}

谢谢。

intellij-idea cucumber cucumber-java
2个回答
3
投票

这是由于步骤定义(|)中的OR符号。

在您的情况下,由于单词“ comment”,它与两个步骤定义都匹配

就像您在IDE中说的那样:查找'我能够添加历史记录'或查找'评论'或查找'项目的详细信息'(对于@Then(“ ^我能够添加历史记录|评论|详细说明item $“))。

对于步骤定义@And(“ ^我添加\”([[^ \“] )\”作为项目的历史记录|注释|详细信息$“)->寻找我添加\”( [^ \“])\”作为历史记录,或查找'评论'或查找'该商品的详细信息'

我在这里看到2种可能的解决方案:

1)您可以尝试以这种方式重构步骤定义,以避免当前情况:

@@ then(“ ^我可以在项目$中添加(历史记录|评论|详细信息)”]

@@(“ ^我添加\”([[^ \“] *)\”作为项目$“的(历史|注释|详细信息))

OR

2)您可以在小黄瓜中使用参数,这样您可以在其中提供任何值,并且不会同时提示您两个步骤的定义

例如:

然后,我可以在项目中添加“将您的价值放在这里”

并且相应的步骤定义将为

 @Then("^I am able to add a \"([^\"]*)\" to the item$")
public void iAmAbleToAddAToTheItem(String arg0) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

(并对第二步进行类似的修改)


0
投票

它们包含很多相同的词,使它们完全不同,并且不会要求您选择。

© www.soinside.com 2019 - 2024. All rights reserved.