简体   繁体   English

在 Cucumber-BDD Java 中,如何一次找出所有 CLASHING 步骤定义? (不在功能文件中使用它们)

[英]In Cucumber-BDD Java, How to find out all CLASHING Step Definitions at once ? (without using them in a feature file)

X, Y and Z below are 3 different Java packages containing Cucumber BDD Step Definitions.下面的 X、Y 和 Z 是 3 个不同的 Java 包,其中包含 Cucumber BDD 步骤定义。

@CucumberOptions(
    features = "classpath:features_for_XYZ",
    glue = {"X", "Y", "Z"},

Since X,Y and Z are developed by different teams, there is a possibility of Step Def clash (ie a step in a feature file could match with more than one Step Definition Java function).由于 X、Y 和 Z 是由不同团队开发的,因此存在 Step Def 冲突的可能性(即特征文件中的一个步骤可能与多个 Step Definition Java 函数匹配)。 Currently such clash is detected only when the step in question is actually used in a feature file.目前只有当该步骤实际用于特征文件时才会检测到这种冲突。

"cucumber.runtime.AmbiguousStepDefinitionsException: ✽.And Following MN thing happens (a/c/d.feature:80) matches more than one step definition:" “cucumber.runtime.AmbiguousStepDefinitionsException: ✽.And 以下 MN 事情发生 (a/c/d.feature:80) 匹配不止一个步骤定义:”

Is there a way to identify all clashing step definitions before using them in a feature file ?在特征文件中使用它们之前,有没有办法识别所有冲突步骤定义?

For each step definition, replace the regex with text that is matched by the regex, then see if it is matched by any other step definitions.对于每个步骤定义,用与正则表达式匹配的文本替换正则表达式,然后查看它是否与任何其他步骤定义匹配。 You'd need to write a framework to do this yourself, since there's no easy way in Cucumber (and you'd need to be careful of for instance writing text where another step will pick up a number; the check will need to be done both ways, and I don't think the replacement can ever be automated to be exhaustive).您需要自己编写一个框架来执行此操作,因为在 Cucumber 中没有简单的方法(并且您需要小心,例如在另一个步骤将选择一个数字的地方编写文本;需要完成检查两种方式,我不认为替换可以自动化到彻底)。

The only other way is by inspection.唯一的其他方法是通过检查。

I'm not sure why you'd want to do this, though.不过,我不确定你为什么要这样做。 Part of the reason we use the word "should" in BDD is because the things that a system "should" do will change over time, and "should" encourages more questioning than "must" or "will".我们在 BDD 中使用“应该”这个词的部分原因是因为系统“应该”做的事情会随着时间的推移而改变,“应该”比“必须”或“将”鼓励更多的质疑。 This means that feature files will change, and maintenance of them is to be expected.这意味着功能文件将发生变化,并且需要对其进行维护。 If a step matches more than one step definition when it's used, it should be enough to change it at the time it's discovered.如果某个步骤时,它使用一个以上的步骤定义相匹配,它应该是足够的,在它的发现时间来改变它。

I'm curious what scenario you're facing that means it isn't.我很好奇你所面临的情况意味着它不是。

You can minimize these clashes by separating feature files and step definitions according to the capabilities and context that the scenarios describe, and by only including steps which match the relevant context.您可以通过根据场景描述的功能和上下文分离特征文件和步骤定义,并仅包含与相关上下文匹配的步骤来最小化这些冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM