Вы находитесь на странице: 1из 12

Gherkin

A language that Cucumber understands


Business Readable
Domain Specific Language

02/07/201
4

Cucumber
Software Tool for testing other software
Automated acceptance tests
Written in a behaviour-driven development (BDD)
style
Written in Ruby programming language
Allows the execution of feature documentation
Written in Business-Facing Text

02/07/201
4

Gherkin
Describes softwares behaviour without the HOW

02/07/201
4

Gherkin - Purpose
Documentation
Automated Tests

02/07/201
4

Gherkin Bonus Feature


When it yells in red, its talking to you
Telling you what code you should write

02/07/201
4

Gherkin Grammar
Defined in the TreeTop grammar
Part of Cucumber Codebase

02/07/201
4

Gherkin Syntax
Feature: Some terse yet descriptive text of what is desired
Textual description of the business value of this feature
Business rules that govern the scope of the feature
Any additional information that will make the feature easier to understand
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too
Scenario: A different situation
...

02/07/201
4

Gherkin Given When Then


Given
A Known State before the User starts interacting with the
System
Avoid talking about User Interaction
Equivalent to PRECONDITIONS in USE CASES
Examples:
Create records (model instances) / set up the database state.
Its ok to call into the layer inside the UI layer here (in Rails: talk to the
models).
Log in a user (An exception to the no-interaction recommendation. Things that
happened earlier are ok).

02/07/201
4

Gherkin Given When Then


When
A Known State before the User starts interacting with the
System
Avoid talking about User Interaction
Equivalent to PRECONDITIONS in USE CASES
Examples:
Create records (model instances) / set up the database state.
Its ok to call into the layer inside the UI layer here (in Rails: talk to the
models).
Log in a user (An exception to the no-interaction recommendation. Things that
happened earlier are ok).

02/07/201
4

Gherkin Feature Definition


Each feature file consists of a single feature
Starts with keyword Feature
Feature contains a list of scenarios
Every scenario consists of a list of steps
Each Scenario starts with one of the keywords:

Given
When
Then
But
And

02/07/201
4

Gherkin Example (1)


Feature: Serve coffee
Coffee should not be served until paid for
Coffee should not be served until the button has been pressed
If there is no coffee left then money should be refunded
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee

02/07/201
4

Gherkin Example (2)


Feature: Division
In order to avoid silly mistakes
Cashiers must be able to calculate a fraction
Scenario: Regular numbers
* I have entered 3 into the calculator
* I press divide
* I have entered 2 into the calculator
* I press equal
* The result should be 1.5 on the screen

02/07/201
4

Вам также может понравиться