cucumber: automating the requirements language you already speak

148
Automating the Requirements Language You Already Speak Ben Mabey @bmabey

Upload: ben-mabey

Post on 01-Nov-2014

6.248 views

Category:

Entertainment & Humor


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Cucumber: Automating the Requirements Language You Already Speak

Automating the Requirements Language You Already Speak

Ben Mabey@bmabey

Page 2: Cucumber: Automating the Requirements Language You Already Speak

Developer

Product Manager

Tester

Designer/UX

Page 3: Cucumber: Automating the Requirements Language You Already Speak

Requirements

Page 4: Cucumber: Automating the Requirements Language You Already Speak

56% of all bugs are introduced in requirements. (CHAOS Report)

Page 5: Cucumber: Automating the Requirements Language You Already Speak

45% of functionality is never used

Page 6: Cucumber: Automating the Requirements Language You Already Speak

Only 20% makes up corefunctionality that is “Always” or “Often” used.

Page 7: Cucumber: Automating the Requirements Language You Already Speak

Feature Devotion

TextPlacing emphasis on features instead of

overall outcomehttp://martinfowler.com/bliki/FeatureDevotion.html

Page 8: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Page 9: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyerI want to refine my searchSo that I can find what I want quickly

Page 10: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyerI want to refine my searchSo that I can find what I want quickly

Feature: Advanced Search

Page 11: Cucumber: Automating the Requirements Language You Already Speak

token for conversation

Page 12: Cucumber: Automating the Requirements Language You Already Speak

Gherkin

Page 13: Cucumber: Automating the Requirements Language You Already Speak

Scenario: titleGiven [Context]When [Action]Then [Expected Outcome]

Page 14: Cucumber: Automating the Requirements Language You Already Speak

Scenario: titleGiven [Context]And [More Context]When [Action]And [Other Action]Then [Expected Outcome]But [Unexpected Outcome]

Page 15: Cucumber: Automating the Requirements Language You Already Speak

Scenario: search by directorGiven 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 16: Cucumber: Automating the Requirements Language You Already Speak

Scenario: no resultsGiven the store has no movies directed by “Steven Spielberg”When I search for “Steven Spielberg”Then I should see “Sorry, but no movies were found”

Page 17: Cucumber: Automating the Requirements Language You Already Speak

Advanced Gherkin

Page 18: Cucumber: Automating the Requirements Language You Already Speak

Scenario: search by director Given movies directed by "Steven Spielberg" are in stock When I search for "Spielberg" under "Director" Then I the search results should be "E.T., and Jaws"

Page 19: Cucumber: Automating the Requirements Language You Already Speak
Page 20: Cucumber: Automating the Requirements Language You Already Speak

Step Tables Scenario: 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 "Spielberg" under "Director" Then I the search results should be "E.T., and Jaws"

Page 21: Cucumber: Automating the Requirements Language You Already Speak

Scenario: 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 "Spielberg" under "Director" Then I should see the following table: | Title | Director | Year | | Jaws | Steven Spielberg | 1975 | | E.T. | Steven Spielberg | 1982 |

Step Tables

Page 22: Cucumber: Automating the Requirements Language You Already Speak

Scenario: 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 "Spielberg" under "Director" Then I the search results should be "E.T., and Jaws"

Page 23: Cucumber: Automating the Requirements Language You Already Speak

Scenario: 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 "Spielberg" under "Director" Then I the search results should be "E.T., and Jaws"

I only want to change the search query and

results part...

Page 24: Cucumber: Automating the Requirements Language You Already Speak

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 25: Cucumber: Automating the Requirements Language You Already Speak

"<Director Query>" "<Search Results>"

Examples: | Director Query | Search Results | | Steve | E.T., Jaws | | George | Dawn of the Dead, Star Wars | | Lucas | Star Wars |

Scenario OutlinesScenario 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 26: Cucumber: Automating the Requirements Language You Already Speak

BackgroundFeature: Account Profile

Scenario: change password success Given I'm logged in ...

Scenario: update contact info Given I'm logged in ...

Page 27: Cucumber: Automating the Requirements Language You Already Speak

BackgroundFeature: Account Profile

Scenario: change password success ...

Scenario: update contact info ...

Background: Given I'm logged in

Page 28: Cucumber: Automating the Requirements Language You Already Speak

Multi-Line String Steps

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 29: Cucumber: Automating the Requirements Language You Already Speak

# language: jaフィーチャ: 加算 バカな間違いを避けるために 数学オンチとして 2つの数の合計を知りたい

  シナリオテンプレート: 2つの数の加算について 前提 <値1> を入力    かつ <値2> を入力    もし <ボタン> を押した    ならば <結果> を表示

  例:    | 値1 | 値2 | ボタン | 結果 |    | 20 | 30 | add | 50 |    | 2 | 5 | add | 7 |    | 0 | 40 | add | 40 |

Page 30: Cucumber: Automating the Requirements Language You Already Speak
Page 31: Cucumber: Automating the Requirements Language You Already Speak

So now what?

Page 32: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Page 33: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Page 34: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 35: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 36: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 37: Cucumber: Automating the Requirements Language You Already Speak

AutomatingGherkin

Page 38: Cucumber: Automating the Requirements Language You Already Speak

project_root/| `-- features

Page 39: Cucumber: Automating the Requirements Language You Already Speak

project_root/| `-- features |-- awesomeness.feature |-- greatest_ever.feature

Page 40: Cucumber: Automating the Requirements Language You Already Speak

project_root/| `-- features |-- awesomeness.feature |-- greatest_ever.feature `-- support |-- env.rb `-- other_helpers.rb

Page 41: Cucumber: Automating the Requirements Language You Already Speak

project_root/| `-- features |-- awesomeness.feature |-- greatest_ever.feature `-- support |-- env.rb `-- other_helpers.rb |-- step_definitions | |-- domain_concept_A.rb | `-- domain_concept_B.rb

Page 42: Cucumber: Automating the Requirements Language You Already Speak

Step

Given a widget

Page 43: Cucumber: Automating the Requirements Language You Already Speak

Step

Given a widgetGiven /^a widget$/ do #codes go hereend

Definition

Page 44: Cucumber: Automating the Requirements Language You Already Speak

When /^I search by director for "([^\"]*)"$/ do |director|end

Page 45: Cucumber: Automating the Requirements Language You Already Speak

When /^I search by director for "([^\"]*)"$/ do |director|end

Regexp Capture -> Yielded Variable

Page 46: Cucumber: Automating the Requirements Language You Already Speak

When /^I search by director for "([^\"]*)"$/ do |director|  visit advanced_search_path  fill_in "By Director", :with => director  click_button "Search"end

Webrat, Webdriver, Watir, etc..

Page 47: Cucumber: Automating the Requirements Language You Already Speak

Not Just for Ruby

Page 48: Cucumber: Automating the Requirements Language You Already Speak

When /^I search by director for "([^\"]*)"$/ do |director|end

[Given(@"^I search by director for \"([^\"]*)\"$")]public void searchDirector(String director) {}

http://wiki.github.com/richardlawrence/Cuke4Nuke/

Page 49: Cucumber: Automating the Requirements Language You Already Speak

Gherkin

Page 50: Cucumber: Automating the Requirements Language You Already Speak

Gherkin Ragel

Page 51: Cucumber: Automating the Requirements Language You Already Speak

Gherkin Ragel

C, C++, Ruby, Java, .net, etc,

Page 52: Cucumber: Automating the Requirements Language You Already Speak

Gherkin Ragel

C, C++, Ruby, Java, .net, etc,

http://specflow.org/

Page 54: Cucumber: Automating the Requirements Language You Already Speak

When("^I search by director for \"([^\"]*)\"$"{ String d ->}

When /^I search by director for "([^\"]*)"$/ do |director|end

When("^I search by director for \"([^\"]*)\"$"{ d: String =>}

@When("^I search by director for \"([^\"]*)\"$")public void searchDirector(String director) {}

(When #"^I search by director for \"([^\"]*)\"$"  (fn [director] ))

Page 55: Cucumber: Automating the Requirements Language You Already Speak

Uhh... this just seems like more work for me.

Page 56: Cucumber: Automating the Requirements Language You Already Speak

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 | | Zombie guy | Dawn of the Dead | | Lucas | Star Wars |

Scenario: search by director on a full moon Given that it is a full moon ...

Page 57: Cucumber: Automating the Requirements Language You Already Speak

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 | | Zombie guy | Dawn of the Dead | | Lucas | Star Wars |

Scenario: search by director on a full moon Given that it is a full moon ...

Page 58: Cucumber: Automating the Requirements Language You Already Speak

You know when you are done.

You know where to begin and end.

Page 59: Cucumber: Automating the Requirements Language You Already Speak

You know when you broke something.

Page 60: Cucumber: Automating the Requirements Language You Already Speak
Page 61: Cucumber: Automating the Requirements Language You Already Speak
Page 62: Cucumber: Automating the Requirements Language You Already Speak

Outside-In

Page 63: Cucumber: Automating the Requirements Language You Already Speak

Model

Page 64: Cucumber: Automating the Requirements Language You Already Speak

Controller

Model

Page 65: Cucumber: Automating the Requirements Language You Already Speak

View

Controller

Model

Page 66: Cucumber: Automating the Requirements Language You Already Speak

View

Controller

Model

UI/UX

Page 67: Cucumber: Automating the Requirements Language You Already Speak

View

Controller

Model

UI/UX

Page 68: Cucumber: Automating the Requirements Language You Already Speak
Page 69: Cucumber: Automating the Requirements Language You Already Speak
Page 70: Cucumber: Automating the Requirements Language You Already Speak

Write Scenarios

Page 71: Cucumber: Automating the Requirements Language You Already Speak

Steps are pending

Page 72: Cucumber: Automating the Requirements Language You Already Speak

Write Step Definition

Page 73: Cucumber: Automating the Requirements Language You Already Speak

Go Down A Gear

Page 74: Cucumber: Automating the Requirements Language You Already Speak

RSpec, xUnit, etc

Page 75: Cucumber: Automating the Requirements Language You Already Speak

Write Unit Test

Page 76: Cucumber: Automating the Requirements Language You Already Speak

Make Unit Test Pass

Page 77: Cucumber: Automating the Requirements Language You Already Speak

REFACTOR!!

Page 78: Cucumber: Automating the Requirements Language You Already Speak

Where Are we?

Page 79: Cucumber: Automating the Requirements Language You Already Speak

Continue until...

Page 80: Cucumber: Automating the Requirements Language You Already Speak

REFACTORand

REPEAT

Page 82: Cucumber: Automating the Requirements Language You Already Speak

Feature: code-breaker submits guess In order to make time pass when I'm alone As a player I want to play the against a machine

Scenario: all correct Given the secret code is "r g y c" When I guess "r g y c" Then the mark should be "bbbb"

submit_guess.feature

Page 83: Cucumber: Automating the Requirements Language You Already Speak

features

srcsubmit_guess.feature

test/java/codebreakerGameSteps.java

Page 84: Cucumber: Automating the Requirements Language You Already Speak

features

srcsubmit_guess.feature

test/java/codebreakerGameSteps.java

$ gem install cucumber$ cucumber features

Page 85: Cucumber: Automating the Requirements Language You Already Speak

<repositories> <repository> <id>cukes</id> <url>http://cukes.info/maven</url> </repository> </repositories>

<pluginRepositories> <pluginRepository> <id>cukes</id> <url>http://cukes.info/maven</url> </pluginRepository> </pluginRepositories>

Page 86: Cucumber: Automating the Requirements Language You Already Speak

<dependencies> <dependency> <groupId>cuke4duke</groupId> <artifactId>cuke4duke</artifactId> <version>0.3.0</version> </dependency> <dependency> <groupId>org.picocontainer</groupId> <artifactId>picocontainer</artifactId> <version>2.8.3</version> </dependency> </dependencies>

Page 87: Cucumber: Automating the Requirements Language You Already Speak

<plugin> <groupId>cuke4duke</groupId> <artifactId>cuke4duke-maven-plugin</artifactId> <configuration> <jvmArgs> <jvmArg> -Dcuke4duke.objectFactory= cuke4duke.internal.java.PicoFactory </jvmArg> </jvmArgs> <cucumberArgs> <cucumberArg>${basedir}/src/test/java</cucumberArg> </cucumberArgs> <gems> <gem>install cuke4duke --version x.y.x</gem> </gems> </configuration> </plugin>

Page 88: Cucumber: Automating the Requirements Language You Already Speak

features

srcsubmit_guess.feature

test/java/codebreakerGameSteps.java

$ mvn integration-test \ -Dcucumber.installGems=true

pom.xml

Page 89: Cucumber: Automating the Requirements Language You Already Speak

Feature: code-breaker submits guess In order to make time pass when I'm alone As a player I want to play the against a machine

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # features/c..s.feature:7 When I guess "r g y c" # features/c..s.feature:8 Then the mark should be "bbbb" # features/c..s.feature:9

1 scenario (1 undefined)3 steps (3 undefined)0m0.076s

Undefined Steps

Page 90: Cucumber: Automating the Requirements Language You Already Speak

You can implement step definitions for undefined steps with these snippets:

@Given("^the secret code is \"([^\"]*)\"$")@Pendingpublic void theSecretCodeIsRGYC_(String arg1) {}

@When("^I guess \"([^\"]*)\"$")@Pendingpublic void iGuessRGYC_(String arg1) {}

@Then("^the mark should be \"([^\"]*)\"$")@Pendingpublic void theMarkShouldBeBbbb_(String arg1) {}

Snippets

Page 91: Cucumber: Automating the Requirements Language You Already Speak

GameSteps.javapackage codebreaker;import cuke4duke.*;

public class CodeBreakerSteps { @Given("^the secret code is \"([^\"]*)\"$") @Pending public void theSecretCodeIs(String code) { }

@When("^I guess \"([^\"]*)\"$") @Pending public void iGuess(String guess) { }

@Then("^the mark should be \"([^\"]*)\"$") @Pending public void theMarkShouldBe(String mark) { }}

Page 92: Cucumber: Automating the Requirements Language You Already Speak

Feature: code-breaker submits guess In order to make time pass when I'm alone As a player I want to play the against a machine

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # public void theS..(..) TODO (Cucumber::Pending) f../c..s.feature:7:in `Given the secret code is "r g y c"' When I guess "r g y c" # public void iGue..(..) Then the mark should be "bbbb" # public void theM..(..)

1 scenario (1 pending)3 steps (2 skipped, 1 pending)0m0.079s

$ mvn integration-test

Page 93: Cucumber: Automating the Requirements Language You Already Speak

Given the secret code is "r g y c" # public void codebreaker.GameSteps .theSecretCodeIs(java.lang.String)

Location

Page 94: Cucumber: Automating the Requirements Language You Already Speak

Steps & Step Definitions

Given the secret code is "r g y c"Step == Method invocation

Page 95: Cucumber: Automating the Requirements Language You Already Speak

Steps & Step Definitions

Given the secret code is "r g y c"

@Given("^the secret code is \"([^\"]*)\"$")public void theSecretCodeIs(String code) { }

Page 96: Cucumber: Automating the Requirements Language You Already Speak

public class GameSteps { private Game game;

@Given("^the secret code is \"([^\"]*)\"$") public void theSecretCodeIs(String code) { game = new Game(code); }}

Implement Intention

Page 97: Cucumber: Automating the Requirements Language You Already Speak

Compilation failure

src/test/java/codebreaker/CodeBreakerSteps.java:[6,12] cannot find symbolsymbol : class Gamelocation: class codebreaker.CodeBreakerSteps

Page 98: Cucumber: Automating the Requirements Language You Already Speak

features

srcsubmit_guess.feature

main/java/codebreakerGame.java

test/java/codebreakerGameSteps.java

Page 99: Cucumber: Automating the Requirements Language You Already Speak

Game.java

package codebreaker; public class Game { public Game(String code) { }}

Page 100: Cucumber: Automating the Requirements Language You Already Speak

Feature: code-breaker submits guess In order to make time pass when I'm alone As a player I want to play the against a machine

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # public void theS..(..) When I guess "r g y c" # public void iGue..(..) TODO (Cucumber::Pending) f../c..s.feature:8:in `When I guess "r g y c"' Then the mark should be "bbbb" # public void theM..(..)

1 scenario (1 pending)3 steps (1 skipped, 1 pending, 1 passed)0m0.112s

$ mvn integration-test

Page 101: Cucumber: Automating the Requirements Language You Already Speak

Repeat process until...

Page 102: Cucumber: Automating the Requirements Language You Already Speak

Feature: code-breaker submits guess In order to make time pass when I'm alone As a player I want to play the against a machine

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # public void theS..(..) When I guess "r g y c" # public void iGue..(..) Then the mark should be "bbbb" # public void theM..(..)

1 scenario (1 passed)3 steps (3 passed)0m0.121s

$ mvn integration-test

Page 103: Cucumber: Automating the Requirements Language You Already Speak

Scenario: all correct Given the secret code is "r g y c" When I guess "r g y c" Then the mark should be "bbbb"

Scenario: 2 wrong pos, 2 correct Given the secret code is "r g y c" When I guess "r g c y" Then the mark should be "bbww"

More Scenarios

Page 104: Cucumber: Automating the Requirements Language You Already Speak

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # public void theS..(..) When I guess "r g y c" # public void iGue..(..) Then the mark should be "bbbb" # public void theM..(..)

Scenario: all correct # features/c..s.feature:6 Given the secret code is "r g y c" # public void theS..(..) When I guess "r g y c" # public void iGue..(..) Then the mark should be "bbbb" # public void theM..(..) org.junit.ComparisonFailure: expected:<bb[bb]> but was:<bb[ww]> (NativeException) codebreaker/CodeBreakerSteps.java:20:in `theMarkShouldBe' features/codebreaker_submits_guess.feature:14:in `Then the mark should be "bbww"'

1 scenario (1 failed, 1 passed)3 steps (1 failed, 3 passed)0m0.121s

Page 105: Cucumber: Automating the Requirements Language You Already Speak

Time to write the

algorithm...

Page 106: Cucumber: Automating the Requirements Language You Already Speak

Scenario: all correct Given the secret code is "r g y c" When I guess "r g y c" Then the mark should be "bbbb"

Scenario: 2 wrong pos, 2 correct Given the secret code is "r g y c" When I guess "r g c y" Then the mark should be "bbww"

DRY?

Page 107: Cucumber: Automating the Requirements Language You Already Speak

Scenario Outline: submit guess Given the secret code is "<code>" When I guess "<guess>" Then the mark should be "<mark>"

Examples: | code | guess | mark | | r g y c | r g y c | bbbb | | r g y c | r g c y | bbww | | r g y c | y r g c | bwww | | r g y c | c r g y | wwww |

Scenario Outline

Page 108: Cucumber: Automating the Requirements Language You Already Speak

More Tricks

Page 109: Cucumber: Automating the Requirements Language You Already Speak

Tags

Page 110: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

Page 111: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

Page 112: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

cucumber --tags ~@proposed

Tag Exclusion

Page 113: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

Page 114: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

cucumber --tags @wip:2 --wip

Page 115: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

cucumber --tags @wip:2 --wip

Limit scenarios in flow

Page 116: Cucumber: Automating the Requirements Language You Already Speak

@store @luceneFeature: Advanced Search ...

@wip Scenario: search by director ...

@proposed @pending_ui Scenario: items not carried ...

@nightly Scenario: long running ...

@third_party Scenario: search Amazon ...

cucumber --tags @wip:2 --wip

Limit scenarios in flow

Expect failure - Success == Failure

Page 117: Cucumber: Automating the Requirements Language You Already Speak

HooksBefore doend

After do |scenario|end

World doend

World(MyModule)World(HerModule)

Page 118: Cucumber: Automating the Requirements Language You Already Speak

Tagged HooksBefore('@im_special', '@me_too') do @icecream = trueend

@me_tooFeature: Lorem Scenario: Ipsum Scenario: Dolor

Feature: Sit @im_special Scenario: Amet Scenario: Consec

Page 119: Cucumber: Automating the Requirements Language You Already Speak

Acceptance Tests ==

End-to-End?

Page 120: Cucumber: Automating the Requirements Language You Already Speak
Page 121: Cucumber: Automating the Requirements Language You Already Speak

Slow

Fast

Page 122: Cucumber: Automating the Requirements Language You Already Speak

Slow

Fast

Integrated

Isolated

Page 123: Cucumber: Automating the Requirements Language You Already Speak

Slow

Fast

Integrated

Isolated

Page 124: Cucumber: Automating the Requirements Language You Already Speak

Slow

Fast

Integrated

Isolated

HtmlUnitV8

Page 125: Cucumber: Automating the Requirements Language You Already Speak

Slow

Fast

Integrated

Isolated

HtmlUnitV8

Page 126: Cucumber: Automating the Requirements Language You Already Speak

What about me?

Page 127: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 128: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 129: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 130: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 131: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

Given... When...Then...

Page 132: Cucumber: Automating the Requirements Language You Already Speak

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

PRD

Dead

Page 133: Cucumber: Automating the Requirements Language You Already Speak

Living

As an impatient buyer

I want to refine my search

So that I can find what

I want quickly

PRD

Dead

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 |

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Page 134: Cucumber: Automating the Requirements Language You Already Speak

Gherkin Subtleties

Page 135: Cucumber: Automating the Requirements Language You Already Speak

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Page 136: Cucumber: Automating the Requirements Language You Already Speak

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Scenario: search by director Given movies directed by "Steven Spielberg" are in stock When I search by director for "Spielberg" Then I should see all of the movies directed by "Steven Spielberg"

Page 137: Cucumber: Automating the Requirements Language You Already Speak

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Scenario: search by director Given movies directed by "Steven Spielberg" are in stock When I search by director for "Spielberg" Then I should see all of the movies directed by "Steven Spielberg"

Declarative

Page 138: Cucumber: Automating the Requirements Language You Already Speak

Scenario: search by director Given movies directed by "Steven Spielberg" are in stock And I am on the "Advanced Search" page When I fill in "Spielberg" for "Director" And press "Submit" Then I should see all of the movies directed by "Steven Spielberg"

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Imperative

Page 139: Cucumber: Automating the Requirements Language You Already Speak

Scenario: search by director Given movies directed by "Steven Spielberg" are in stock And I am on the "Advanced Search" page When I fill in "Spielberg" for "Director" And press "Submit" Then I should see all of the movies directed by "Steven Spielberg"

Feature: Advanced Search As an impatient buyer I want to refine my search So that I can find what I want quickly

Imperative

I like it! I actually know how a user can use it!

Page 140: Cucumber: Automating the Requirements Language You Already Speak

Balance Abstraction

Page 141: Cucumber: Automating the Requirements Language You Already Speak

Scenario: successful login Given I'm on the login page When I fill in "jimmy" for "Login" And fill in "password" for "Password" And click "Login" Then I should see "Welcome back jimmy!"

Page 142: Cucumber: Automating the Requirements Language You Already Speak

Scenario: change password success

Page 143: Cucumber: Automating the Requirements Language You Already Speak

Scenario: change password success Given I'm on the login page When I fill in "jimmy" for "Login" And fill in "password" for "Password" And click "Login" Then I should see "Welcome back jimmy!"

Page 144: Cucumber: Automating the Requirements Language You Already Speak

Scenario: change password success Given I'm on the login page When I fill in "jimmy" for "Login" And fill in "password" for "Password" And click "Login" Then I should see "Welcome back jimmy!" When I click "Change Password" And fill in the following | Old Password | password | | New Password | brand-new | | Confirmation | brand-new | And click "Change Password" Then I should see "Your password has been changed."

Page 145: Cucumber: Automating the Requirements Language You Already Speak

Scenario: change password success When I click "Change Password" And fill in the following | Old Password | password | | New Password | brand-new | | Confirmation | brand-new | And click "Change Password" Then I should see "Your password has been changed."

Given I'm on the login page When I fill in "jimmy" for "Login" And fill in "password" for "Password" And click "Login" Then I should see "Welcome back jimmy!"

Incidental Details

Page 146: Cucumber: Automating the Requirements Language You Already Speak

Scenario: change password success Given I'm logged in When I click "Change Password" And fill in the following | Old Password | password | | New Password | brand-new | | Confirmation | brand-new | And click "Change Password" Then I should see "Your password has been changed."

Hide the noise!

Page 148: Cucumber: Automating the Requirements Language You Already Speak

Thanks!BenMabey.com

github.com/bmabey

Twitter: bmabey