小智 13
还应该注意到'Before'和'After'是全局钩子,即那些钩子是为你的功能文件中的每个场景运行的
如果你想为几个测试用例(按标签分组)运行设置和拆解,那么你需要使用taggedHooks,其中语法是
Before('@cucumis, @sativus') do
# This will only run before scenarios tagged
# with @cucumis OR @sativus.
end
AfterStep('@cucumis', '@sativus') do
# This will only run after steps within scenarios tagged
# with @cucumis AND @sativus.
end
Run Code Online (Sandbox Code Playgroud)
有关更多信息:https://github.com/cucumber/cucumber/wiki/Hooks
ord*_*rde 11
您可以使用在每个方案之后运行的After 钩子:
After do
## teardown code
end
Run Code Online (Sandbox Code Playgroud)
还有一个Before钩子,允许您在场景之前设置状态和/或测试数据:
Before do
## setup code
end
Run Code Online (Sandbox Code Playgroud)
前后钩提供的功能setup和teardown从Test::Unit,他们一般都位于hooks.rb在features/support目录中.