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?
How to find Cucumber steps that are not used
Asked Answered
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.
Please post the full stack trace –
Smite
I found this in the cucumber book last night and apparently it doesn't load the env.rb file which explains why things are failing. I was able to get it to run after moving things around and it's exactly what I want. Thanks! –
Ivan
I think I ended up using
-f usage
instead of -f stepdefs
though. –
Ivan If you have "@wip" features this will report any steps used in those as unused. does anyone know how to include "@wip" features in this build? –
Homeless
Can you elaborate on what things needed to be moved around? I get the same uninitialized constant error, but with capybara. –
Surly
To fix errors @PeterBrown alluded to, I added
require_relative "env"
to the top of the first file alphabetically in features/support/
(I'm guessing cucumber loads the support files alphabetically for some reason) –
Avina Thanks @NathanWallace. The reason for this is the
--dry-run
flag, which omits loading env.rb (as stated in the cucumber --help
). –
Dynamometry Hi guys, Is there a way to detect all steps in feature files that do not have any step definition methods? Like a check that returns list of all step sentences from feature files? –
Jockey
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.
For me
cucumber-js --dry-run --format usage
did the job.
Output print is something like
│ some feature test name │ UNUSED │ src\step_definitions\team-edit-steps.ts:24│
© 2022 - 2024 — McMap. All rights reserved.
Using the default profile... uninitialized constant Object::Factory (NameError)
– Ivan