Cucumber 场景的清理步骤 [英] Cleanup steps for Cucumber scenarios
问题描述
有没有办法为 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
中的 setup
和 teardown
的功能,它们一般位于 >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屋!