简体   繁体   中英

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.

@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). 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:"

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).

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". 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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