Behave
Behavior Driven
Design
with Behave
http://germaniumhq.com
bogdan.mustiata@germaniumhq.com
Bogdan Mustiata (@bmst)
Overview
●
Introduction
●
Gherkin
●
Behave
●
Demo
Overview
●
Introduction
●
Gherkin
●
Behave
●
Demo
Introduction
What is BDD?
Introduction
Story: Returns go to stock
As a store owner
In order to keep track of stock
I want to add items back to stock when they're
returned.
Scenario 1: Refunded items should be returned to stock
Given that a customer previously bought a black sweater
from me
And I have three black sweaters in stock.
When he returns the black sweater for a refund
Then I should have four black sweaters in stock.
Introduction
Story: Returns go to stock
As a store owner
In order to keep track of stock
I want to add items back to stock when they're
returned.
Scenario 1: Refunded items should be returned to stock
Given that a customer previously bought a black sweater
from me
And I have three black sweaters in stock.
When he returns the black sweater for a refund
Then I should have four black sweaters in stock.
Introduction
Overview
●
Introduction
●
Gherkin
●
Behave
●
Demo
Gherkin
●
A natural language
●
Only a specification
Gherkin / Specification
●
Feature
●
Scenario (use cases)
– Given
– When
– Then
●
Scenario Outline
Gherkin
Feature: Some terse yet descriptive text of what is desired
@BusinessCritical @Meh
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
Gherkin
Demo
Creating a feature file
Gherkin
●
Implementations:
●
Behave (python)
●
JCucumber (java)
●
Cucumber-JS (nodejs)
●
Cucumber (ruby)
●
JBehave
Gherkin
●
Implementations:
●
Behave (python)
●
JCucumber (java)
●
Cucumber-JS (nodejs)
●
Cucumber (ruby)
●
JBehave
Overview
●
Introduction
●
Gherkin
●
Behave
●
Demo
Behave
●
Python implementation
●
pip install behave (python 2.7+)
●
Decorators for Gherkin
●
@given
●
@when
●
@then
●
@step
Behave
●
features/*.feature
●
features/steps/*.py
●
features/environment.py
Behave Context
●
Context Levels
●
All
●
Feature
●
Scenario
●
Automatic Cleanup on same level
●
Context inheritance
●
All Feature Scenario→ →
Behave Lifecycle
●
features/environment.py
●
All (before_all, after_all)
●
Feature (before_feature, after_feature)
●
Scenario (before_scenario, after_scenario)
●
Step (before_step, after_step)
●
Tag (before_tag, after_tag)
●
features/steps/*.py
●
@step/@given/@when/@then
Behave Context
●
Context Levels
●
All
●
Feature
●
Scenario
●
Automatic Cleanup on same level
●
Context inheritance
●
All Feature Scenario→ →
Behave Run
●
Behave
●
-t (specify tags to run, not = ~)
●
--no-capture
Overview
●
Introduction
●
Gherkin
●
Behave
●
Demo
Demo
Demo
Implementing a feature test with behave
FIN
Questions?

Behave