Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Cucumber steps that are not used

Tags:

I've been working with Cucumber for about a year and have been continually refactoring the features and step definitions along the way. I have tons of steps defined across many files and I can't help but feel like many of them are no longer needed. Is there a way to find which cucumber step definitions are no longer being used?

like image 560
Peter Brown Avatar asked Jan 23 '12 01:01

Peter Brown


People also ask

How do you check if all the steps have step definition before execute in Cucumber?

An annotation followed by the pattern is used to link the Step Definition to all the matching Steps, and the code is what Cucumber will execute when it sees a Gherkin Step. Cucumber finds the Step Definition file with the help of the Glue code in Cucumber Options.

What is used to check if all the steps have the step definition before execute?

Dry Run is nothing but checking the complete implementation of all the mentioned steps present in the Feature file. Before the execution starts . Dry Run is Checking the implementionation not about the execution of scripts.

How do you find the current step name in Cucumber?

The scenario name can be retrieved using the getName() function.

What happens if Cucumber does not find a matching step definition?

If Cucumber is telling you that your steps are undefined, when you have defined step definitions, this means that Cucumber cannot find your step definitions. You'll need to make sure to specify the path to your step definitions (glue path) correctly.


1 Answers

The stepdefs formatter can do this, e.g.:

cucumber --dry-run -f stepdefs 

It will print 'NOT MATCHED BY ANY STEPS' for any non-matches.

If you have any steps that are only used by other steps, then omit --dry-run to get accurate results. With --dry-run, the steps are not executed and cucumber will not find out that the referred step is actually used.

like image 188
Andy Waite Avatar answered Dec 17 '22 03:12

Andy Waite