Cucumber方案的清理步骤 [英] Cleanup steps for Cucumber scenarios

查看:166
本文介绍了Cucumber方案的清理步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来定义一个功能在黄瓜的所有场景的清理步骤?我知道 Background 用于定义跟随它的每个场景的设置步骤,但是有没有办法定义在每个场景结束时发生的事情?

Is there a way to define the cleanup steps for all of the scenarios for a feature in Cucumber? I know that Background is used to define the setup steps for each scenario that follows it, but is there a way to define something like that to happen at the end of each scenario?

推荐答案

您可以使用钩子,将在每个场景后运行:

You can use an After hook that will run after each scenario:

After do
  ## teardown code
end

还有一个Before钩子,允许你设置状态和/在场景之前:

There's also a Before hook that will allow you to set up state and/or test data prior to the scenario:

Before do
  ## setup code
end

Before和After钩子提供 setup teardown Test :: Unit ,它们通常位于 hooks.rb features / support 目录中。

The Before and After hooks provide the functionality of setup and teardown from Test::Unit, and they are generally located in hooks.rb in the features/support directory.

这篇关于Cucumber方案的清理步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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