如何查找未使用的 Cucumber 步骤
我使用 Cucumber 已有大约一年的时间,并且一直在不断重构功能和步骤定义。我在许多文件中定义了大量步骤,但我忍不住觉得其中许多步骤不再需要。有没有办法找到哪些黄瓜步骤定义不再被使用?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
stepdefs 格式化程序可以执行此操作,例如:
对于任何不匹配的情况,它将打印“NOT MATCHED BY ANY STEPS”。
如果您有任何步骤仅被其他步骤使用,则省略
--dry-run
以获得准确的结果。使用--dry-run
时,这些步骤不会被执行,并且 cucumber 不会发现实际使用了引用的步骤。The stepdefs formatter can do this, e.g.:
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.您可以尝试在 simplecov 等覆盖工具下运行您的故事。
默认情况下,它可能会排除测试代码,例如黄瓜步骤,因为通常人们感兴趣的是覆盖了多少应用程序代码,而不是测试代码的多少,但这应该很容易逆转。
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
did the job.
Output print is something like