问题
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?
回答1:
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.
回答2:
You could try running your stories under a coverage tool such as simplecov.
By default it will probably exclude test code such as cucumber steps since normally one is interested in how much of the app code is covered rather than how much of the test code, but that should be easy to reverse.
来源:https://stackoverflow.com/questions/8966367/how-to-find-cucumber-steps-that-are-not-used