背景
我目前正在为Symfony2网页编写behat tests(Mink / Selenium)。我有很多例子,实际上写它们应该没问题。步骤定义已经写好了。
但是,在示例中,有时会定义Scenario:
,有时会定义Scenario Outline:
问题:
这两种定义测试的方法有什么区别?
答案 0 :(得分:13)
复制和粘贴场景以使用不同的值很快就会变得乏味和重复:
Scenario: Eat 5 out of 12 Given there are 12 cucumbers When I eat 5 cucumbers Then I should have 7 cucumbers Scenario: Eat 5 out of 20 Given there are 20 cucumbers When I eat 5 cucumbers Then I should have 15 cucumbers
场景大纲允许我们通过使用带占位符的模板更简洁地表达这些示例
Scenario Outline: Eating Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers Examples: | start | eat | left | | 12 | 5 | 7 | | 20 | 5 | 15 |
“场景大纲”步骤提供了一个永远不会直接运行的模板。对于其下方的“示例”部分中的每一行,都会运行一次“场景大纲”(第一个标题行除外)。
Writing Features指南中的更多内容。
答案 1 :(得分:0)
答案 2 :(得分:0)
Intellij IDEA + Cucumber支持这一点,但我不知道这是否适合所有人。
Feature: LoginFeature
This feature deals the login functionality of the application
Scenario: Login with correct username and password
Given I navigate to the login page
And I enter the following for Login
| username | password |
| admin | adminpassword |
| admin2 | adminpassword2 |
| admin3 | adminpassword3 |
| admin4 | adminpassword4 |
| admin5 | adminpassword5 |
And I click login button
Then I should see the userform page