TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
BDD and Behave
1.
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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 re
if re.match('http(s?)://.+', url) is None:
url = context.base_url + url
context.browser.get(url)
8. Why Use BDD
Document features
Better requirements
Know what is broken
Know how to reproduce a failure
Have confidence that your application works
9. Why Use Behave
Generates skeleton step code
Reusable steps without function knowledge
Provides a clean context between scenarios
Multiple verb support