Cucumber方案的清理步骤 [英] Cleanup steps for Cucumber scenarios
问题描述
有没有一种方法来定义一个功能在黄瓜的所有场景的清理步骤?我知道 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屋!