behaviour driven development - cuking the agile world
DESCRIPTION
This slide deck is what I spoke on in Agile India week conference in Oct 2013 at PuneTRANSCRIPT
www.unicomlearning.com
India Agile Week-201326-Oct-2013 at Pune
BDD in an Agile world
Gaurav Awasthi
Senior Architect and Technology Evangelist
www.agileinbusiness.com
www.unicomlearning.comConcept, Practice, Tools
UNICOM Presents
India Agile Week-2013
Concept, Practice and finally Tools
Concepts are beyond Practices and Tools
Good Tools are better suited to Practices which help internalize Concepts quickly
www.unicomlearning.comThe BDD World…
UNICOM Presents
India Agile Week-2013
Concepts Write software that matters In close collaboration with Stakeholder
Practices Writing features, scenarios Write executable specs
Tools Cucumber JBehave RSpecs
www.unicomlearning.comBDD…by definition
UNICOM Presents
India Agile Week-2013
BDD is a second-generation, outside-in, multiple-stakeholder, 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 North
www.unicomlearning.comBuzzword Agnostic Benefits…
UNICOM Presents
India Agile Week-2013
• Seamless mapping between Requirement statements and executable tests
• Specification by example
• Loose grammar of the domain
• Brings Testers/QA to the forefront of development process
• Self verifying documentation
• Evolves behavior as the domain understanding changes
www.unicomlearning.comCo-existence with TDD
UNICOM Presents
India Agile Week-2013
TDD
Write a failing unit test Make the
test pass
Refactor
BDD
Write a failing feature test
TDD – Develop it the right way
BDD – Develop the right thing
www.unicomlearning.comAnd what about DDD ?
UNICOM Presents
India Agile Week-2013
• Domain Driven Design • Ubiquitous Language• gives vocabulary• Inside Out
• Behavior Driven Development• Sentences out of the vocabulary• Description of the behavior• Outside In
www.unicomlearning.comThe BDD Practice
UNICOM Presents
India Agile Week-2013
1. Describe the behavior in plain text – Features and Scenarios
2. Write a step definition for each Step
3. Run it and watch it fail
4. Write code to make the step pass
5. Run it again and see the step pass
6. Repeat step 2 – 5 until green like a Cuke
7. Repeat step 1 – 6 until the money runs out
www.unicomlearning.comThe Tool - Cucumber
UNICOM Presents
India Agile Week-2013
Why Cucumber ?
• one of the least technical tools
• a very active open source project
• supports a variety of languages
www.unicomlearning.com
UNICOM Presents
India Agile Week-2013
• JBehave -> ported to Ruby -> RBehave -> rewritten from scratch -> RSpec -> + story runner -> Cucumber -> Cucumber-JVM
• Aslak Hellesoy ported Cucumber to Java (cucumber-jvm)
• Cucumber comes with Ruby (the original), Java, .NET, Adobe Flex, Python, Perl, Erlang, PHP
• Full stack for acceptance tests include – Browser Driver and Browser
Slicing Cucumber
www.unicomlearning.comGherkin
UNICOM Presents
India Agile Week-2013
• A Business Readable, Domain Specific Language that Cucumber understands
• Line-based language that Cucumber uses to define behaviors in the form of features, scenarios, and steps
• Serves 3 purposes :• Automated Tests• Documentation• Specs for Code to be written
• Source files have .feature extension. Single Gherkin source file contains a description of a single feature
www.unicomlearning.comGherkin syntax Feature : title
UNICOM Presents
India Agile Week-2013
As a [ person or role who will benefit ]
I want [ some feature ]
So that [ benefit or value of the feature ]
www.unicomlearning.comGherkin syntax Scenario : title
UNICOM Presents
India Agile Week-2013
Given [ some initial context ]
When [ an event occurs]
Then [ ensures some outcome ]
www.unicomlearning.comExample
UNICOM Presents
India Agile Week-2013
Feature: Customer purchases a device
• As a Customer• I want to purchase a Bluetooth
device• So that I can make or receive a
hands free call
Scenario : Customer has a credit note valued more than the receipt amount
• Given the customer is on the till
• And he has a credit note of Rs 1000
• And the receipt amount is Rs 500
• When the balance amount is paid
• Then the billing completes
www.unicomlearning.comCucumber Options
UNICOM Presents
India Agile Week-2013
@RunWith(Cucumber.class) @Cucumber.Options (
tags = “@focus”,features= “classpath:billing.feature”
) public class CukeRunner { }
Some common options : • features – path to the feature files• glue – where to look for step definition and hooks• tags – what tags in the features should be executed• format – what formatters to use• …
www.unicomlearning.comCLI Option
UNICOM Presents
India Agile Week-2013
• Several Runners• Command Line Interface cucumber-core• JUnit Runner cucumber-junit• Android Runner cucumber-android
• java cucumber.cli.Main [options] [FILE|DIR]• --glue , --format, --tags, --name …
• Benefit :• Independent of JUnit• Integration with Ant
www.unicomlearning.comDemo Code
UNICOM Presents
India Agile Week-2013
• Create a maven project, with cucumber-jvm related dependencies
• cucumber-core, cucumber-java, cucumber-junit• Write a Feature and a scenario with steps
• Feature: Withdrawing money from a User account• Scenario: Withdrawing money from a User's account should
reduce money in the current balance• Given a User has $100 in his account• When $50 is withdrawn from the account• Then the balance should be $50
• Write Java wrapper class – like CukeRunner, • annotated with RunWith and Cucumber.Options
• Run the class, let it fail• Implement Steps, Run again• See it green like a cuke
www.unicomlearning.comAnd the debate
UNICOM Presents
India Agile Week-2013
To TDD, To BDD or
To prefer one over the other
www.unicomlearning.comReferences
UNICOM Presents
India Agile Week-2013
• That's not BDD, that's just Cucumber by Chris Parsons• Introducing BDD by Dan North• http://dannorth.net/whats-in-a-story/ by Dan North• http://cukes.info/install-cucumber-jvm.html• http://cukes.info/api/cucumber/jvm/javadoc/cucumber/api/junit/
Cucumber.Options.html
www.unicomlearning.com
THANK YOU
India Agile Week-2013Organized by
UNICOM Trainings & Seminars Pvt. Ltd. [email protected]
Speaker name: Gaurav AwasthiEmail ID: [email protected]