英文:
After feature hook in cucumber feature files
问题
Cucumber不支持像Background那样支持after_feature hook的具体原因是什么?我们有几种情况,如果有这个功能的话,将会非常理想。
例如,假设在一个feature文件中有多个场景涉及数据库更新。在每个场景的末尾,应该将这些数据库更新还原。但是,如果某个场景失败,还原部分将无法执行。这可能会导致后续场景的失败。
现在我们正在使用步骤定义级别的After钩子来还原场景标签级别的更改。但我们更希望这可以在feature文件中完成,因为步骤定义是参数化的。
另一个选择是防止在步骤定义中使用硬断言,以确保整个场景都被执行。
英文:
Is there a specific reason for cucumber to not to support after_feature hook like Background. We have several use cases where it would have been ideal if we had this feature.
e.g. Suppose multiple scenarios in a feature file does db updates. At the end of each scenario those db updates should be reverted back. Whenever there's a failure in a scenario, reverting part cannot be done. This can cause failures in subsequent scenarios
Now we are using step definition level After hooks to revert scenario tag level changes. But we prefer if this can be done in feature file itself since step definitions are parameterized.
Other option is to prevent using hard asserts in step definitions so that it is guaranteed entire scenario is executed.
答案1
得分: 0
尽管 Background
处理测试设置阶段,但它通过业务步骤来集中在场景的特定业务步骤上。
这与 Before
钩子不同。后者处理测试准备的技术方面(以及 After
钩子)。
由于业务用户通常不关心业务层下面的数据库清理或任何技术细节,因此在功能文件级别暴露这种控制级别是没有意义的。
英文:
Despite Background
addresses test set-up phase it operates with business steps in order to concentrate on specific business steps of a scenario.
It is not the same as Before
hook. The latter addresses technical aspect of test preparation (as well as After
hook).
Since business users normally do not care of database clean up or any technical stuff underneath the business layer, it does not make sense to expose such level of control on feature file level.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论