bdd, cucumber and freinds

40
Frank Duan Kinesis 2010

Upload: frank-duan

Post on 05-Jul-2015

180 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Bdd, cucumber and freinds

Frank Duan

Kinesis

2010

Page 2: Bdd, cucumber and freinds

Introduction to BDD

Introduction to Cucumber

Stories and Cucumber features

Building Cucumber Scenarios and Steps

Tools

Slicing Cucumber

Cucumber Catalyst

Page 3: Bdd, cucumber and freinds

FAIL

Page 4: Bdd, cucumber and freinds

“I believe that the hardest part of software projects, the most common source of project failure, is communication with the customers and users of that software.

By providing a clear yet precise language to deal with domains, a DSL can help improve this communication.”

Martin Fowler

Page 5: Bdd, cucumber and freinds

To meet requirement

To guarantee quality

verify confidence Design Behaviour

Page 6: Bdd, cucumber and freinds

GAP

Page 7: Bdd, cucumber and freinds
Page 8: Bdd, cucumber and freinds

Outside-In

Page 9: Bdd, cucumber and freinds
Page 10: Bdd, cucumber and freinds
Page 11: Bdd, cucumber and freinds
Page 12: Bdd, cucumber and freinds

Feature

Page 13: Bdd, cucumber and freinds
Page 14: Bdd, cucumber and freinds

Scenario

Scenario: title

Given [Context]

And [More Context]

When [Action]

And [Other Action]

Then [Expected Outcome]

But [Unexpected Outcome]

Page 15: Bdd, cucumber and freinds
Page 16: Bdd, cucumber and freinds

A story

Page 17: Bdd, cucumber and freinds

Token for Conversation

Page 18: Bdd, cucumber and freinds

Meet Gherkin

Page 19: Bdd, cucumber and freinds

Scenario: search by director

Given the store has movies directed by “Steven Spielberg”

When I search for “Steven Spielberg”

Then I should see all of the movies directed by “Steven Spielberg”

Page 20: Bdd, cucumber and freinds

Meet Advanced Gherkin –TABLEScenario: search by directorGiven the following movies are in stock:| Title | Director | Year || Jaws | Steven Spielberg | 1975 || Star Wars | George Lucas | 1975 || Dawn of the Dead | George Romero | 1978 || E.T. | Steven Spielberg | 1982 |

When I search for "Spielberg" under "Director"Then I should see the following table:

| Title | Director | Year || Jaws | Steven Spielberg | 1975 || E.T. | Steven Spielberg | 1982 |

Page 21: Bdd, cucumber and freinds

Meet Advanced Gherkin –Multi-Line String

Scenario: register successfully

Given I am on on the registration page

When I sign up as "Jojo Binks"

Then I should receive the following email:

"""

Thanks for signing up Jojo!

Important information about here.

"""

Page 22: Bdd, cucumber and freinds

Meet Advanced Gherkin –Scenario Outlines

Scenario Outline: search by director

Given the following movies are in stock:

| Title | Director | Year |

| Jaws | Steven Spielberg | 1975 |

| Star Wars | George Lucas | 1975 |

| Dawn of the Dead | George Romero | 1978 |

| E.T. | Steven Spielberg | 1982 |

When I search for "<Director Query>" under "Director"

Then I the search results should be "<Search Results>"

Examples:

| Director Query | Search Results |

| Steve | E.T., Jaws |

| George | Dawn of the Dead, Star Wars |

| Lucas | Star Wars |

Page 23: Bdd, cucumber and freinds

Building step definition (Example)

Scenario: Create a new company

Given I am logged in

When I create a new company named Acme

Then I should see that a company named Acme exists

Page 24: Bdd, cucumber and freinds

Building step definition – Given

Given == Setup

Given "I am logged in" douser = Factory(:user)

visits new_session_path

fills_in ‘Login’, :with => user.login

fills_in ‘Password’, :with => user.password

clicks_button ‘Login’

end

Page 25: Bdd, cucumber and freinds

Building step definition – When

When == Change

When "I create a new company named $name" do |name|

visits new_company_path

fills_in 'Name', :with => name

clicks_button 'Create'

end

Page 26: Bdd, cucumber and freinds

Building step definition – Then

Then == Outcome

Then "I should see that a company named $name exists" do |name|

response.body.should =~ Regexp.new(name)

end

Page 27: Bdd, cucumber and freinds

Hooks – Before and After Generic hooks or hooks by tags

Background

Page 28: Bdd, cucumber and freinds

Adpating rspec DSL for validation

DOESN’T adpate rspec mock module

Use factory_girl instead

Page 29: Bdd, cucumber and freinds

factory_girl: load data into database for test

Given "I am logged in" douser = Factory(:user)visits new_session_pathfills_in ‘Login’, :with => user.loginfills_in ‘Password’, :with => user.passwordclicks_button ‘Login’

end Factory.sequence(:email) {|n| "user#{n}@example.com" }Factory.define :user do |user|

user.name 'User'user.email { Factory.next(:email) }user.login {|u| u.email }user.password 'password'user.password_confirmation 'password'

end

Page 30: Bdd, cucumber and freinds

Simulating or drive Browsers

Feature on Javascript test

Flexibility on switching drivers to achieve different test demand

Flexibility on switching between css and xpath selector

Covering most of the popular browser driving

Remote calling (for IE test on VM)

Page 31: Bdd, cucumber and freinds

Highlight keywords in Gherkin

Autocomplete by hotkey

Run by hotkey and present visual report

Page 32: Bdd, cucumber and freinds

A DRb server for testing frameworks (RSpec / Cucumber currently) that forks before each run to ensure a clean testing state.

Page 33: Bdd, cucumber and freinds

Soren knows all about that : s

Page 34: Bdd, cucumber and freinds

Lazy coverage-aware running of Cucumber acceptance tests

Run a scenario if it needs to

Page 35: Bdd, cucumber and freinds

Distributed testing framework

Spread your tests over processors and/or multiple machines to test your code faster

Page 36: Bdd, cucumber and freinds

Don’t force structure

Avoid Noise!

Avoid Inconsistency

Balance Abstraction

Page 37: Bdd, cucumber and freinds

Building step abstraction from steps

Tagging

Tagging for focused testing

Tagging for categorizing test by purpose and environs

Tagging for loading capybara configuration

Page 38: Bdd, cucumber and freinds

Slow builds are the enemy of continuous integration

Reuse – Spork, Cucover

Run Just Enough Tests

Slicing Features with tags

Just enough Database and try NullDB

Distributed testing - hydra

Page 39: Bdd, cucumber and freinds

The Rspec Book

http://www.slideshare.net/josephwilk/rocket-fuelled-cucumbers

http://www.slideshare.net/bkeepers/behavior-driven-development-with-cucumber-presentation

http://www.slideshare.net/josephwilk/cucumbered

http://www.slideshare.net/bmabey/cucumber-automating-the-requirements-language-you-already-speak

Page 40: Bdd, cucumber and freinds

Thanks for your patience