tushman.io

The musings of an insecure technologist

PyCon Proposal - Pragmatic Behavior Driven Development

Pragmatic Behavior Driven Development

Description

Love your test suite again (or for the first time).

Have you ever met a developer who loves their test suite for their web app. There is subtle air of confidence surrounding them. They stand a bit taller; walk with a bit of a swagger.

This talk will put you on that path, by showing an approach of Behavior Driven Development using lettuce and selenium

Detailed Abstract

Behavior Driven Development (BDD) is a development process based on Test-Driven Development – but makes a significant modification. With TDD – the main goal was to achieve test-coverage (what percentage of your code is covered by tests). With BDD – the driving question – “What percentage of my user stories are covered?” The main test-unit is the user story.

1
2
3
4
5
6
7
8
9
10
11
Story: Returns go to stock  

In order to keep track of stock 
As a store owner 
I want to add items back to stock when they're returned  

Scenario 1: Refunded items should be returned to stock 
Given a customer previously bought a black sweater from me 
And I currently have three black sweaters left in stock 
When he returns the sweater for a refund 
Then I should have four black sweaters in stock

With an application that leverages BDD, will have a set of feature files, and a feature file will have a collection of stories written is a specific format Given, When, Then.

Python has some tooling that helps turn this format into a fully automated test framework. We use lettuce to process feature files, and selenium to drive the web browser.

Outline:

Pragmatic Behavior Driven Development

Description

Love your test suite again (or for the first time).

Have you ever met a developer who loves their test suite for their web app? There is subtle air of confidence surrounding them. They stand a bit taller; walk with a bit of a swagger.

This talk will put you on that path by showing an approach of Behavior Driven Development using lettuce and selenium.

Detailed Abstract

Behavior Driven Development (BDD) is a development process based on Test-Driven Development – but makes a significant modification. With TDD – the main goal was to achieve test coverage (what percentage of your code is covered by tests). With BDD the driving question is “What percentage of my user stories are covered?” The main test unit is the user story.

1
2
3
4
5
6
7
8
9
10
11
Story: Returns go to stock  

In order to keep track of stock 
As a store owner 
I want to add items back to stock when they're returned  

Scenario 1: Refunded items should be returned to stock 
Given a customer previously bought a black sweater from me 
And I currently have three black sweaters left in stock 
When he returns the sweater for a refund 
Then I should have four black sweaters in stock

With an application that leverages BDD, we will have a set of feature files, and a feature file will have a collection of stories written is a specific format: Given, When, Then.

Python has some tooling that helps turn this format into a fully automated test framework. We use lettuce to process feature files and selenium to drive the web browser.

Outline:

  1. Intro (5 mins)
    1. Who am I?
    2. 20 years of development and testing, and what I have seen over time
    3. Explain why BDD is an important evolution
  2. Writing your first Test (5 mins)
    1. Explain the Gherkin Format (Given, When, Then)
    2. Write your first test – watch it fail
  3. Given / When / Then (15 mins)
    1. Given: Using Factories to set up your data
    2. When: Trigger Events
    3. Then: Writing “Deterministic” assertions
  4. Setting up your testing environment (10 mins)
    1. The terrain.py file
    2. Work around javascript timing issues with a selenium adaptor
  5. Other tools to flesh out your test suite (5 mins)
    1. Coverage
    2. Flake8
    3. Travis (or CI)
    4. Unit Test Frameworks (such as nose)

Additional Notes:

  • My parallelized version of lettuce is open sourced here
  • I have other open-source libraries, can find them here
  • This is my first time speaking at PyCon. I have spoken at Boston Python. My slides for that talk are here
  • I sometimes write about Python. My blog is here

Comments