给定如下的Feature文件:
Feature: Coffee improves mood in the background
Background:
Given the user drank coffee
Scenario Outline: Coffee changes peoples moods
Then user <USER> should be <MOOD>
Examples:
| USER | MOOD |
| Michael | happy |
| Elvis | electrified |
| John | sad |
背景测试步骤“用户喝咖啡”应该运行1次,还是3次?
答案 0 :(得分:4)
看看下面的人为答案。在输出中,您将看到后台步骤执行了3次。
feature.rb:
Feature: Does a background run before each scenario outline?
Background:
When I'm a background step
Scenario Outline: foo
Then I should print '<count>'
Examples:
|count|
| 10 |
| 20 |
| 30 |
step_def.rb:
When(/^I'm a background step$/) do
print "BACKGROUND EXECUTED"
end
Then(/^I should print '(\d+)'$/) do |num|
# empty step
end
输出:
Feature: Does a background run before each scenario outline
BACKGROUND EXECUTED Background: # features/login.feature:3
When I'm a background step # features/step_definitions/login.rb:1
Scenario Outline: foo # features/login.feature:6
Then I should print '<count>' # features/login.feature:7
Examples:
| count |
| 10 |
BACKGROUND EXECUTED | 20 |
BACKGROUND EXECUTED | 30 |
3 scenarios (3 passed)
6 steps (6 passed)