58
Hello BDD! Hello BDD! ANTONIO ROBRES TURON

Hello bdd

Embed Size (px)

DESCRIPTION

Introduction to BDD

Citation preview

Page 1: Hello bdd

Hello BDD!Hello BDD!ANTONIO ROBRES TURON

Page 2: Hello bdd

Given a speaker with name Toni

When he is giving his conference

Then you should not fall asleep

Page 3: Hello bdd
Page 4: Hello bdd

BDD

EDD

ATDD

DDD

SPECIFICATION BY

EXAMPLE

AGILE ACCEPTANCE

TEST

EXECUTABLE

SPECIFICATIONS

STORY TELLING

Page 5: Hello bdd

Index

•Why born BDD?•What is BDD?•How use BDD?•Benefits•Demo

Page 6: Hello bdd

BDD HISTORY

Page 7: Hello bdd

First approach

TDD Test Drive Development0 Is not a tool!!!! It’s a design methodology0 Focused in unit testing 0 Life cycle

0Red 0Green 0Refactor

0 Something is missing:0THINK!0Think Red Green Refactor

Page 8: Hello bdd

TDD is fine but…

• Is programmer focused• Only take care about the source code• Helps to write code right but not right code• Not support communication0 Inside team (including QA, BA, Data analyst…)

0With stakeholders• Is bottom – up process

Page 9: Hello bdd

BDD History

BDD was developed by Dan North as a response to the issues encountered teaching TDD

0 Where to start in the process0 What to test and what not to test0 How much to test in one go0 What to call the tests0 How to understand why a test fails0 Give you reliability your tests?

Page 10: Hello bdd

BDD History

• The first proposes was that the unit testing names be whole sentences starting with the word SHOULD and written in order of business value.0Every class should do something

• ClientDetailsValidatorTest0ShouldFailForMissingSurname0ShouldFailForMissingAge

Page 11: Hello bdd

What is BDD?

Page 12: Hello bdd

Definition

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

• Using examples to create a shared understanding and surface uncertainly to deliver software that matters.

Page 13: Hello bdd

How use BDD?

Page 14: Hello bdd

Story

•What’s an story?It has to be a description of a requirement and its

business benefit, and a set of criteria by which we all agree that it is “done” (Dann North)

•Written in business language

Page 15: Hello bdd

Story

• Structure:0 Title (one line describing the story)0 Narrative:

0As a [role]0 I want [feature]0So that [benefit]

Page 16: Hello bdd

Story

Example:0 As a user 0 I want to publish a tweet0 So that share information with my followers

Page 17: Hello bdd

Story

Another template:0 Title (one line describing the story)0 Narrative

0 In order to [benefit]0As a [role]0 I want to [feature]

Page 18: Hello bdd

Story

Example:0 In order to share information with my followers0 As a user 0 I want to publish a tweet

Page 19: Hello bdd

Scenario

• It’s the acceptance criteria• It’s a description of each specific case

of the narrative• Can be used to help discover the scope

of the story or the feature• The scenario should be described in

terms of Givens, Events and Outcomes

Page 20: Hello bdd

Scenario

Structure:0 Title (one line describing the scenario)0 Narrative

0Given [context]0And [some more context]...0When  [event]0Then  [outcome]0And [another outcome]...

Page 21: Hello bdd

Scenario

Example:Given a twitter account activated

When I send a tweet with 139 characters

Then the tweet is published

And all my followers can read the tweet

Page 22: Hello bdd

How to build scenarios?

Only 4 keywords have the empowerment to build scenarios

0 but something is missing…

What is the most powerful tool to build the scenarios?

Page 23: Hello bdd
Page 24: Hello bdd

Having conversations

Page 25: Hello bdd

User Story & Scenario Example

Title: Customer withdraws cashAs a customer,I want to withdraw cash from an ATM,so that I don’t have to wait in line at the bank.

Scenario 1: Account is in creditGiven the account is in creditAnd the card is validAnd the dispenser contains cashWhen the customer requests cashThen ensure the account is debitedAnd ensure cash is dispensedAnd ensure the card is returned

Page 26: Hello bdd

User Story & Scenario Example

Scenario 2: Account has insufficient funds

Given the account is overdrawnAnd the card is validWhen the customer requests cashThen ensure a rejection message is displayedAnd ensure cash is not dispensedAnd ensure the card is returned

Page 27: Hello bdd

User Story & Scenario Example

Scenario 3: Card has been disabled

Given the card is disabled

When the customer requests cashThen the ATM should retain the card

And the ATM should say the card has been retained

Page 28: Hello bdd

Tools

• Python 0 Should-DSL0 Lettuce0 Pycuke

• Java0 Jbehave0 Concordion

• Ruby0 Cucumber

• Others0 Fitnesse0 Tartare

Page 29: Hello bdd

BDD life cycle

Page 30: Hello bdd

BDD Life cycle

• Let’s choose a problem  Given a number, what is its factorial?• User Story:

0 Feature: Compute factorial 0 In order to learn BDD0As beginners 0We'll implement factorial

Page 31: Hello bdd

BDD Life cycle

•Writte the first scenario:• Scenario: Factorial of 0

0Given I have the number 0 0When I compute its factorial 0Then I see the number 1

Page 32: Hello bdd

BDD Life cycleDefine steps in python (or another language):

Page 33: Hello bdd

BDD Life cycle

Run and watch it fail

Page 34: Hello bdd

BDD Life cycle Write code to make it pass:

Page 35: Hello bdd

BDD Life cycle

Run again and watch it pass:

Page 36: Hello bdd

BDD Life cycle

Add the another scenarios:0 Scenario: Factorial of 1

0Given I have the number 1 0When I compute its factorial 0Then I see the number 1

0 Scenario: Factorial of 2 0Given I have the number 2 0When I compute its factorial 0Then I see the number 2

Page 37: Hello bdd

BDD Life cycle0We don’t need change the steps in python because we haven’t changed the definition

Page 38: Hello bdd

BDD Life cycleWrite code to make it pass:

Page 39: Hello bdd

BDD Life cycle

Execute!

Page 40: Hello bdd

BDD Life cycle

• We can add more scenarios and improve the software quality:0 What happen when we introduce a character?0 What happen when we introduce a float?0 What happen when we not introduce nothing?0 …

Page 41: Hello bdd

BDD Life cycleRefactor your scenarios and source code:

Page 42: Hello bdd

BDD Life cycle

First:0 Analyze the feature

•Google API about geography codification:0 We want offer a product to improve the geography

knowledge0 As a user we need a product that when a city is

introduced the application returns the country.

Page 43: Hello bdd

BDD Life cycle

0User story:0 As a user0 I want know the country code of one city0 In order to improve my geography knowledge

Page 44: Hello bdd

BDD Life cycle

• We start thinking about the possible scenarios to build the acceptance criteria:0 What happen if the city not exists?0 What happen if the city parameter is null?0 What happen if the city is mispelled 0 Should the request be authenticated?

Page 45: Hello bdd

BDD life cycle

Scenario Outline: Retrieve the geolocation with city name given Given a <city> name When I request the geoencoding of the city Then I obtain the <city> name with the <country_code>

Examples: | city | country_code | | Barcelona | ES | | Paris | FR | | San+Francisco | US |

Page 46: Hello bdd

BDD life cycle

• Code the scenario!• Every line in the scenario is a function or

method in the code.0 Given: Preconditions settings0 When: API request 0 Then: Assertions

Page 47: Hello bdd

BDD life cycle

• Execute:

Page 48: Hello bdd

BDD life cycle

• Build the source code

• Remember build only the source code required to pass the scenario

• If something is not required, delete it

Page 49: Hello bdd

BDD life cycle

Execute:

Page 50: Hello bdd

BDD life cycle

Refactor:0 Give feedback to the stakeholders and the whole team0 Refactor the source code to improve it!0 Refactor the scenarios 0 Add new scenarios

Page 51: Hello bdd

BDD life cycle

Page 52: Hello bdd

BENEFITS

Page 53: Hello bdd

Communication

Improve communication0 BDD is about conversations0 Ubiquitous language (shared between stakeholders and

whole team)0 Collaboration between stakeholders, Bussiness

Analysts, QA and programmers

Speak the same language = building toguether

Page 54: Hello bdd

Documentation

• Formal documentation is not required• Scenarios can be used as a software

documentation• Every time the software changes… the

scenarios should be changed also (red, green, refactor)

Live Documentation!!!!

Page 55: Hello bdd

Other benefits

• Only code the required functionality (YAGNI)

• Quick feedbackIf the tests are included in the CI

• Involve stakeholders in the implementation process

• Develop code right and right code• Give confidence in your code refactors

Page 56: Hello bdd

Resources0 http://dannorth.net0 http://lizkeogh.com0 http://

www.slideshare.net/ajaydanait1/behavior-driven-development-bdd-16779998

0 http://behaviour-driven.org/0 http://cukes.info/0 http://lettuce.it/0 http://fitnesse.org/0 http://www.concordion.org/0 http://jbehave.org/0 User Stories Applied: For Agile Software Development, Mike Cohn0 Agile Testing: A Practical Guide for Testers and Agile Teams, Lisa

Crispin and Janet Gregory0 Specification by Example, Gojko Adzic

Page 57: Hello bdd

Questions?

Page 58: Hello bdd

Contact

Twiiter: @twiindan

Email: [email protected]

Linkedin: http://es.linkedin.com/in/antoniorobres

Web: www.softqatest.com