10 things about bdd, cucumber and specflow
TRANSCRIPT
Seb RoseCucumber [email protected] things you need to know aboutBDD, Cucumber and Specflow
@sebrose http://cucumber.io
@sebrose http://claysnow.co.uk
0. A little bit of BDD history
@sebrose http://claysnow.co.uk
A little bit of historyAgile- waterfall & failures- lightweight & feedback- manifesto & Scrum- mini waterfalls & continuing failures- short iterations & continuous learningBDD
While using and teaching agile practices like test-driven development (TDD) on projects in different environments, I kept coming across the same confusion and misunderstandings.
Dan Northc. 2002http://dannorth.net/introducing-bdd/
@sebrose http://claysnow.co.ukChris Matts and Dan North discuss the power of should on a flight back from Agile Development Conference 2004
@sebrose http://claysnow.co.uk
FitNesseshould not test: JUnit+ Chris Matts -> JBehaveCucumber Ruby
I decided it was time to put my money or at least my time where my mouth was. I started writing a replacement for JUnit called JBehave, which removed any reference to testing and replaced it with a vocabulary built around verifying behaviour.
Dan Northhttp://dannorth.net/introducing-bdd/
@sebrose http://claysnow.co.uk
Dans post - 2006
BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology.
It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.Dan Northhttp://skillsmatter.com/podcast/java-jee/how-to-sell-bdd-to-the-business
@sebrose http://claysnow.co.uk1. Different names, same idea
@sebrose http://claysnow.co.uk
Myth - BDD is not the same as TDD, SBE, ATDD
http://lizkeogh.com/2011/06/27/atdd-vs-bdd-and-a-potted-history-of-some-related-stuff/Whats the difference between TDD, ATDD, BDD and SbE?Theyre called different things
@sebrose http://claysnow.co.uk
Difference between BDD and TDD... the intended audience might be different
2. Tools are NOT essential
@sebrose http://claysnow.co.uk
Myth - BDD is about tools & automation
BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology.
It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.Dan Northhttp://skillsmatter.com/podcast/java-jee/how-to-sell-bdd-to-the-business
@sebrose http://claysnow.co.ukhaving conversations is more important than capturing conversations is more important than automating conversations
Liz Keoghhttp://lizkeogh.com/2014/01/22/using-bdd-with-legacy-systems/
@sebrose http://claysnow.co.uk
Its not about tools
http://lizkeogh.com/2011/03/04/step-away-from-the-tools/Have enough conversations to know how to get started. Find out where the riskiest bits are, and where the system behaves unusually. Chat. Discuss. Discover. Work out how, and when, youre going to get feedback on the work youre about to do.Then, and only then, reach for the tools.Liz Keogh
@sebrose http://claysnow.co.ukhttp://www.acceptic.com/blog/wp-content/uploads/2013/09/bdd.jpg3. Collaboration IS essential
@sebrose http://claysnow.co.uk
So, if its not about the tools, what is BDD?
https://cucumber.pro/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool.htmlWhen you do BDD/Specification by Example and Outside-in, regression tests fall out at the other end. They are a by-product of those activities. Testing isn't the activity itself.
Cucumber is first a foremost a collaboration tool that aims to bring a common understanding to software teams - across roles.Aslak Hellesy
@sebrose http://claysnow.co.ukIdeasUser Stories
Automated TestsCode
@sebrose http://claysnow.co.uk
- 3 Amigos- Collaboration- Examples
- Living documentation, executable specification
http://www.developersurvivalguide.com/tag/agile/
@sebrose http://claysnow.co.uk
Fit it into your process
4. Cucumber is simple
@sebrose http://claysnow.co.uk
Describe Cucumber scenarios- G/W/T (working backwards from examples)- Feature files- Step definitions- Regular expressions- Parameter conversions- Signalling failures
Core concepts
FeaturesScenariosStepsGherkinGlue codeStep definitionsJava / C#
Application
Each scenario is an example
@sebrose http://claysnow.co.ukFeature: 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 10Given I register a teamThen my score is 0Given I register a teamAnd I start playing a gameWhen I submit a correct easy answerThen my score is 10
@sebrose http://claysnow.co.uk
This is called Gherkin
Given(/^I register a team$/) do pending endRuby
@sebrose http://claysnow.co.ukimport cucumber.api.java.en.*;import cucumber.api.PendingException;
public class HikerStepDef {
@Given("^I register a team$") public void iRegisterATeam() throws Throwable { throw new PendingException(); }}Java
@sebrose http://claysnow.co.ukusing TechTalk.SpecFlow;
[Binding]public class GameSteps{ [Given(@"I register a team")] public void GivenIRegisterATeam() { ScenarioContext.Current.Pending(); }}C#
@sebrose http://claysnow.co.uk
5. Cucumber and Specflow arent exactly the same
@sebrose http://claysnow.co.uk
Differences between Cucumber and SpecFlow- maintainers- G/W/T namespaces- Contexts- Code Behind- Test frameworks- Hooks
Given/When/Then namespaces
Global namespace - Given/When/Then interchangeableSeparate namespaces - Given/When/Then distinct- And/But bind to preceding namespace- [StepDefinition] for compatibility
@sebrose http://claysnow.co.uk
GWT namespaces
Sharing data between steps
Varies by implementation- Ruby: World object- Java: Dependency InjectionContext object(s)- Injected- Scenario- Feature
@sebrose http://claysnow.co.uk
Sharing data
Hooks
Before & AfterRuby: Around, AfterStepBefore & AfterBeforeStep & AfterStepBeforeFeature & AfterFeatureBeforeTestRun & AfterTestRunBeforeScenarioBlock & AfterScenarioBlock
@sebrose http://claysnow.co.uk
Hooks
Tagged hooks: allOrdering: Java only
https://cemarking.net/wp-content/uploads/2014/01/User-Manual_featured.jpg6. Prefer living documentation
@sebrose http://claysnow.co.uk
Organising feature filesNon-executable documentation vs. executable specification / living documentation
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
@sebrose http://claysnow.co.uk
Stories are disposableFeatures/Scenarios evolve but are persistent specification of system Not all work items are User StoriesTrack them using cards if it helps, but dont ask PO to prioritise them
Other forms of documentation are also necessary!
@sebrose http://claysnow.co.uk
7. Dont forget the testers
@sebrose http://claysnow.co.uk
Myth BDD means we can get rid of the testers
http://claysnow.co.uk/architectural-alignment-and-test-induced-design-damage-fallacy/
@sebroseclaysnow.co.uk
@sebrose http://claysnow.co.uk
@sebrose http://claysnow.co.uk
http://1.bp.blogspot.com/_YzKCMr-tcMM/TFLIGeqTJfI/AAAAAAAAARQ/AhNW62KX5EA/s1600/cartoon6.jpg8. BDD is not just for testers
@sebrose http://claysnow.co.ukSupport code
FeaturesScenariosStepsGherkinGlue codeStep definitionsJava / C#
Application
SupportCode
@sebrose http://claysnow.co.uk
Support codeNeed dev skills
Ubiquitous Language
@sebrose http://claysnow.co.uk
The team owns the ubiquitous language
9. The right amount of detail
@sebrose http://claysnow.co.ukImperativeDeclarative
Keep it Focussed: Avoid incidental details
@sebrose http://claysnow.co.ukFeature: Sign up Scenario: New user redirected to their own page Given I am not logged in And I visit the homepage And I follow "Sign up" And I fill in "Username" with "Matt" And I fill in "Password" with "password" And I fill in "Confirm password" with "password" When I press "Sign up" Then I should be on my feeds page And I should see "Hello, Matt"
@sebrose http://claysnow.co.uk
Emphasise the likely need for detail somewhere else.
Feature: Sign up Scenario: New user redirected to their own page When I sign up for a new accountThen I should be taken to my feeds pageAnd I should see a greeting message
@sebrose http://claysnow.co.uk(A great blog post on this subject by Dan North)http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/Whose domain is it anyway?
@sebrose http://claysnow.co.uk10. Deliberate practice
@sebrose http://claysnow.co.uk
@sebrose http://claysnow.co.uk
@sebrose http://claysnow.co.uk11. Conference time ;)Which long running agile conference is being held in Edinburgh in May?
ELISABETH HENDRICKSON * LIONEL BRIAND * MARY POPPENDIECK * NAT PRYCE * STEVE FREEMAN * BERTRAND MEYER * BRIAN MARICK * DAN NORTH * KATHERINE KIRK * DAVE FARLEY * DAVID EVANS * DIANA LARSEN * EOIN WOOD * JUTTA ECKSTEIN * KEVLIN HENNEY * MICHAEL FEATHERS * RACHEL DAVIES * REBECCA WIRFS-BROCK * SANDRO MANCUSO * WOODY ZUILL@XPConf http://xp2016.org#xp2016
@sebrose http://claysnow.co.uk
Which major agile conference is being held in Edinburgh next year?
01 BDD demands collaboration
10 Examples facilitate feedback102 things you should know
@sebrose http://claysnow.co.ukSeb Rose
Twitter: @sebrose
Blog: www.claysnow.co.uk
E-mail:[email protected]
@sebrose http://claysnow.co.uk