behaviour driven development - cuking the agile world

20
www.unicomlearning.com India Agile Week-2013 26-Oct-2013 at Pune BDD in an Agile world Gaurav Awasthi Senior Architect and Technology Evangelist www.agileinbusiness.com

Upload: gaurav-awasthi

Post on 01-Nov-2014

1.246 views

Category:

Technology


1 download

DESCRIPTION

This slide deck is what I spoke on in Agile India week conference in Oct 2013 at Pune

TRANSCRIPT

Page 1: Behaviour Driven Development - Cuking the Agile world

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

Page 2: Behaviour Driven Development - Cuking the Agile world

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

Page 3: Behaviour Driven Development - Cuking the Agile world

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

Page 4: Behaviour Driven Development - Cuking the Agile world

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

Page 5: Behaviour Driven Development - Cuking the Agile world

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

Page 6: Behaviour Driven Development - Cuking the Agile world

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

Page 7: Behaviour Driven Development - Cuking the Agile world

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

Page 8: Behaviour Driven Development - Cuking the Agile world

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

Page 9: Behaviour Driven Development - Cuking the Agile world

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

Page 10: Behaviour Driven Development - Cuking the Agile world

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

Page 11: Behaviour Driven Development - Cuking the Agile world

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

Page 12: Behaviour Driven Development - Cuking the Agile world

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 ]

Page 13: Behaviour Driven Development - Cuking the Agile world

www.unicomlearning.comGherkin syntax Scenario : title

UNICOM Presents

India Agile Week-2013

Given [ some initial context ]

When [ an event occurs]

Then [ ensures some outcome ]

Page 14: Behaviour Driven Development - Cuking the Agile world

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

Page 15: Behaviour Driven Development - Cuking the Agile world

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• …

Page 16: Behaviour Driven Development - Cuking the Agile world

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

Page 17: Behaviour Driven Development - Cuking the Agile world

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

Page 18: Behaviour Driven Development - Cuking the Agile world

www.unicomlearning.comAnd the debate

UNICOM Presents

India Agile Week-2013

To TDD, To BDD or

To prefer one over the other

Page 19: Behaviour Driven Development - Cuking the Agile world

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

Page 20: Behaviour Driven Development - Cuking the Agile world

www.unicomlearning.com

THANK YOU

India Agile Week-2013Organized by

UNICOM Trainings & Seminars Pvt. Ltd. [email protected]

Speaker name: Gaurav AwasthiEmail ID: [email protected]