Cucumber 场景的清理步骤 [英] Cleanup steps for Cucumber scenarios

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

问题描述

有没有办法为 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?

推荐答案

你可以使用 After hook 那将在每个场景之后运行:

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 钩子提供 Test::Unit 中的 setupteardown 的功能,它们一般位于 >hooks.rbfeatures/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天全站免登陆