SpecFlow is quite a recent addition to the software development toolbox. Sometimes it feels like we’re using a hammer to drive in a screw, so in this session we’ll explore what it’s good for and when to use it. We’ll also look at what problems it doesn’t help with and when not to use it.
As you might expect, I’m a huge fan of using SpecFlow, as part of a well thought out approach to Behaviour Driven Development (BDD) or Specification By Example (SBE). I’ve also seen the pain of organisations who have tried using SpecFlow from a pure test automation perspective, and this is one of the misapplications that we’ll talk about.
We’ll look at a further 9 specific, actionable recommendations for using SpecFlow well, including how to write maintainable executable specifications, organising large suites of specifications in an accessible way, and where SpecFlow fits into an Agile development process.
By the end of this session you’ll know enough to decide whether your problems are more like a screw or a nail – and whether SpecFlow is the right tool.
9. @sebrose h)p://cucumber.io
While using and teaching agile pracUces
like test-driven development (TDD) on
projects in different environments, I kept
coming across the same confusion and
misunderstandings.
Dan North
c. 2002
h)p://dannorth.net/introducing-bdd/
12. @sebrose h)p://cucumber.io
At the end of 2003, I decided it was Ume
to put my money – or at least my Ume –
where my mouth was. I started wriUng a
replacement for JUnit called JBehave,
which removed any reference to tesUng
and replaced it with a vocabulary built
around verifying behaviour.
Dan North
h)p://dannorth.net/introducing-bdd/
15. @sebrose h)p://cucumber.io
Given/Then/When sees the light of day
Acceptance Criteria:
Prevent cash withdrawal when overdrawn
Given successfully login from user login
and the account is in overdrawn [balance = -50]
When the user requests cash [request 20]
Then refuse cash
and return card
abc.truemesh.com/archives/2004_11.html
24. @sebrose h)p://cucumber.io
BDD is a second-generaUon, outside-
in, pull-based, mulUple-stakeholder,
mulUple-scale, high-automaUon, agile
methodology.
It describes a cycle of interacUons with
well-defined outputs, resulUng in the
delivery of working, tested soEware
that ma)ers.
Dan North
h)p://skillsma)er.com/podcast/java-jee/how-to-sell-bdd-to-the-business
27. @sebrose h)p://cucumber.io
The best TDD
pracUUoners...
Work from the outside-in, i.e. test-first
Use examples to clarify their requirements
Develop and use a ubiquitous language
30. @sebrose h)p://cucumber.io
BDD is a second-generaUon, outside-
in, pull-based, mulUple-stakeholder,
mulUple-scale, high-automaUon, agile
methodology.
It describes a cycle of interacUons with
well-defined outputs, resulUng in the
delivery of working, tested soEware
that ma)ers.
Dan North
h)p://skillsma)er.com/podcast/java-jee/how-to-sell-bdd-to-the-business
31. @sebrose h)p://cucumber.io
having conversa*ons
is more important than
capturing conversa*ons
is more important than
automa3ng conversa*ons
Liz Keogh
h)p://lizkeogh.com/2014/01/22/using-bdd-with-legacy-systems/
39. @sebrose h)p://cucumber.io
Feature: Team Scoring
Teams start with zero score.
Correct answer gets points depending on
how difficult it is.
Scenario: Score starts at 0
Given I register a team
Then my score is 0
Scenario: Correct easy answer scores 10
Given I register a team
And I start playing a game
When I submit a correct easy answer
Then my score is 10
Given I register a team
Then my score is 0
Given I register a team
And I start playing a game
When I submit a correct easy answer
Then my score is 10
49. @sebrose h)p://cucumber.io
Binding & test frameworks
Behind the scenes
- may need to specify paths
- select required plugin(s)
Some magic code generaUon
- NUnit by default
- configuraUon changes for others
- several output opUons
50. @sebrose h)p://cucumber.io
Sharing data between steps
Varies by implementaUon
- Ruby: World object
- Java: Dependency InjecUon
Context object(s)
- Injected
- Scenario
- Feature
54. Acceptance
criteria
User Story
Examples
Feature: Team Scoring
Teams start with zero score.
Correct answer gets points depending on
how difficult it is.
Scenario: Score starts at 0
Given I register a team
Then my score is 0
Scenario: Correct easy answer scores 10
Given I register a team
When I submit a correct easy answer
Then my score is 10
Scenario: Correct hard answer scores 50
Given I register a team
When I submit a correct hard answer
Then my score is 50
63. @sebrose h)p://cucumber.io
“I get paid for code that works, not for tests, so
my philosophy is to test as li8le as possible to
reach a given level of confidence ...
“I suspect this level of confidence is high
compared to industry standards”
h)p://stackoverflow.com/quesUons/153234/how-deep-are-your-unit-tests/153565#153565
66. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: Sign up
Scenario: Create a new user account
Given I am not logged in
And I visit the homepage
And I follow "Sign up"
And I fill in "Username" with "Seb"
And I fill in "Password" with "password"
And I fill in "Confirm password" with "password"
When I press "Sign up"
Then a new account should be created for me
67. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: Sign up
Scenario: Create a new user account
Given I am not logged in
And I decide to sign up for an account
And I provide an acceptable username
And I provide an acceptable password
And I confirm my password choice
When I submit these details
Then a new account should be created for me
68. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: Sign up
Scenario: New user redirected to their own page
Given I am not logged in
And I decide to sign up for an account
And I provide an acceptable username
And I provide an acceptable password
And I confirm my password choice
When I submit these details
Then I should be on my feeds page
And I should see "Hello, Seb"
69. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: Sign up
Scenario: New user redirected to their own page
Given I am not logged in
And I decide to sign up for an account
And I provide an acceptable username
And I provide an acceptable password
And I confirm my password choice
When I submit these details
Then I should be on my feeds page
And I should see a greeting message
70. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: Sign up
Scenario: New user redirected to their own page
When I sign up for a new account
Then I should be taken to my feeds page
And I should see a greeting message
71. @sebrose h)p://cucumber.io
Imperative vs
Declarative Style
Feature: The entire system
This feature illustrates what can happen when you
take the declarative style too far.
Scenario: It works
When I use the system
Then it should work perfectly
72. @sebrose h)p://cucumber.io
(A great blog post on this subject by Dan North)
h)p://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
Whose domain is it
anyway?