Cucumber学习笔记1
上一篇 /
下一篇 2013-08-23 23:02:19
Gherkin Basics:
Feature
Feature: login
#The following is multiline description(which called Feature Injection template) of Feature
In order to use the system
As I am a system account holder
I want to login
#end
notice: In valid Gherkin, a Feature must be followed by one of the following:
Scenario,Scenario Outline,Background
Background
A background section in a feature file allows you to specify a set of steps that are common to every scenario in the file. Instead of having to repeat those steps over and over for each scenario, you move them up into a Background element.
Scenario
it’s valid Gherkin to follow the name with a multiline description—everything up until the first Given, When, or Then will be slurped up into the description of the scenario
Each scenario name must make sense and be able to be executed independently of any other scenario.
Scenario: Successful withdrawal from an account in credit
Given I have $100 in my account # the context
When I request $20 # the event(s)
Then $20 should be dispensed # the outcome(s)
Given
we use Given to set up the context where the scenario happens
When
we use When to interact with the system somehow
Then
we use Then to check that the outcome of that interaction was what we expected.
And&But
Each of the lines in a scenario is known as a step. We can add more steps to each Given, When, or Then section of the scenario using the keywords And and But.
Although you can use this way:
Given
Given
it's the same as:
Given
And/But
Scenario Outline & Example
Feature: Adding
Scenario Outline: Add two numbers
Given the input "<input>"
When the calculator is run
Then the output should be "<output>"
Examples:
| input | output |
| 2+2 | 4 |
| 98+1 | 99 |
by using Scenario Outline & example,we can parameterlize the
test data so as to run a variety of data under the Scenario Outline.In this example,Scenario will run twice,first time is with the input "2+2" and output "4",another is the input "98+1" and output "99"
We can use Gherkin in our own spoken language such as Chinese:
# language: zh-CN
cucumber --i18n help #display all language code
cucumber --i18n XX(language code) #check the keyword of the language
to be continued
收藏
举报
TAG: