Ranjith's
Ranjith's

Reputation: 4730

How to detect unused step definitions in cucumber-jvm junit project?

I'm running automation tests using cucumber-junit project and i've roughly around 200 scenario's in my project.. now the problem is, it's hard to find unused step definitions in my project as we constantly need to update features.. Is there any solution to detect step definitions that is no longer useful.. Any help much appreciated!!

Upvotes: 1

Views: 2633

Answers (3)

karoisuzvards
karoisuzvards

Reputation: 21

Since cucumber-jvm 4.4.0 it is possible to use cucumber-jvm built in plugin - unused.

for cucumber junit runner it could look like this:

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {
        "json:build/report/cucumber.json",
        "unused:build/report/usage.txt"} //mind this plugin
    glue = "stepdefs",
    features = "features"
)
public class CucumberRunner {
}

After run unused stepdefs should be found in build/report/usage.txt

Original pull request: https://github.com/cucumber/cucumber-jvm/pull/1648

Upvotes: 2

GaurZilla
GaurZilla

Reputation: 373

There can be a case where a single step can be a part of different scenarios and will have single method only in step definition. So, It is easy to map the feature file's step with the corresponding method while executing the feature file using 'cucumber feature' pulg-in.

However, It is literally not possible to cross validate the same from step definition file to identify the single step in number of feature files.

Perhaps, The only possible way out is to design your application in modular way:

1) with feature files and corresponding step definition files specific to a specific feature/module. 2) Keep generic methods in a generic parent step definition file.

Thus, Designing the application in a modular way can easily lead you to identify the unused methods that can be removed from the step definitions.

Upvotes: 1

Mykola Gurov
Mykola Gurov

Reputation: 8695

IntelliJ's cucumber plugin can search for usages of a step definition. It will not give you all unused ones in one go, but at least you can check individual usages one by one. The plugin is also available in the Community Edition of IDEA.

Upvotes: 0

Related Questions