在每个功能之前和之后是否有一个黄瓜钩子可以运行 [英] Is there a cucumber hook to run before and after each feature

查看:19
本文介绍了在每个功能之前和之后是否有一个黄瓜钩子可以运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在每个带有特定标签的黄瓜功能之前和之后运行特定的代码块?

Is there a way to run specific code block before and after each cucumber feature with certain tag?

由于设置过程非常昂贵,我不想在每个场景之前运行它.

Since setup process is very expensive I don't want to run it before each scenario.

推荐答案

前几天我和 Matt Wynne(cucumber gem 的核心团队成员之一)谈过,他告诉我 cucumber 没有这个功能(在撰写本文时).

Few days ago I've spoke with Matt Wynne (one of the core team member of cucumber gem) and he told me that there is no such feature in cucumber (at the time of writing this).

作为一种解决方法,他建议标记整个功能并在每个钩子之前使用这样的标志:

As a workaround he suggested to tag whole feature and use before each hook with a flag like so:

Before('@feature_with_expensive_setup') do
  unless @setup_is_done
    # perform expensive setup code here ..
    @setup_is_done = true
  end
end

这篇关于在每个功能之前和之后是否有一个黄瓜钩子可以运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆