BDD and Behave

10

Transcript of BDD and Behave

Page 1: BDD and Behave
Page 2: BDD and Behave

Who Am I?

Developer/Evangelist at LaunchKey

Founder/Co-Organizer of Las Vegas PHP UG

Co-Organizer of Las Vegas Developer UG

#vegastech enthusiast

Testanista

Page 3: BDD and Behave

What is BDD?

Behavior Driven Development is developing for

required application behavior

BDD utilizes tests who’s result are in a plain

language understood by the business

BDD uses Extreme Programming (XP) based

features and scenarios to accomplish both goals

Page 4: BDD and Behave

Why Use BDD?

BDD tests all the things

BDD only tests what matters

BDD makes it easy to understand what’s not working

BDD documents requirements in the system

Page 5: BDD and Behave

What is Behave?

Python implementation of the Cucumber specification

Uses Gherkin as the Domain Specific Language (DSL) to allow for writing tests in plain language

Uses decorators and regular expressions to match steps with underlying code base

Allows for reusable step code

Page 6: BDD and Behave

Example Gherkin

Feature: Home Page

Scenario: Login Link

Given I am on the homepage

When I click " Login"

Then I will be on the "LaunchKey | Log in" page

Page 7: BDD and Behave

Example Step

from behave import *

use_step_matcher("re")@when(u'(?P<ignore>I )go to "(?P<url>[^"]*)"')@given(u'(?P<ignore>I )am on "(?P<url>[^"]*)"')def step_impl_go_to(context, url, **args):

import reif re.match('http(s?)://.+', url) is None:

url = context.base_url + urlcontext.browser.get(url)

Page 8: BDD and Behave

Why Use BDD

Document features

Better requirements

Know what is broken

Know how to reproduce a failure

Have confidence that your application works

Page 9: BDD and Behave

Why Use Behave

Generates skeleton step code

Reusable steps without function knowledge

Provides a clean context between scenarios

Multiple verb support

Page 10: BDD and Behave

https://www.slideshare.net/AdamEnglander/bdd-and-

behave

http://spkr8.com/t/56641

http://pythonhosted.org/behave/

@adam_englander

#launchkey on freenode.net

#vegastech on freenode.net

[email protected]