intellij-idea - IntelliJ 要求在不同的 Cucumber 步骤之间选择声明
问题描述
我有两个步骤有一些相似之处,但并不完全以相同的方式表达。但是,IntelliJ 一直要求我在它们之间进行选择,就好像它们是重复的一样,不知道为什么?
@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());
}
谢谢你。
解决方案
这是因为步骤定义 ( | ) 中的 OR 符号。
在您的情况下,由于“评论”一词,它与两个步骤定义都匹配
就像您对 IDE 说的:查找“我能够添加历史记录”或查找“评论”或查找“项目的详细信息”(对于 @Then("^I am able to add a history|comment |项目的详细信息$"))。
对于步骤定义@And("^I add \"([^\"] )\" 作为项目$") 的历史|评论|详细信息 -> 查找 I add \"([^\" ] )\" 作为历史记录或查找“评论”或查找“项目的详细信息”
我在这里看到两种可能的解决方案:
1)您可以尝试以这种方式重构步骤定义以避免当前情况:
@Then("^我可以将(历史|评论|详细信息)添加到项目$")
@And("^I 添加 \"([^\"]*)\" 作为项目$"的 (history|comment|details))
或者
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();
}
(并对第二步进行类似的修改)