Hello bdd

Preview:

DESCRIPTION

Introduction to BDD

Citation preview

Hello BDD!Hello BDD!ANTONIO ROBRES TURON

Given a speaker with name Toni

When he is giving his conference

Then you should not fall asleep

BDD

EDD

ATDD

DDD

SPECIFICATION BY

EXAMPLE

AGILE ACCEPTANCE

TEST

EXECUTABLE

SPECIFICATIONS

STORY TELLING

Index

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

BDD HISTORY

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

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

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?

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

What is 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.

How use 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

Story

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

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

Story

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

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]

Story

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

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

Scenario

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

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

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

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?

Having conversations

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

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

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

Tools

• Python 0 Should-DSL0 Lettuce0 Pycuke

• Java0 Jbehave0 Concordion

• Ruby0 Cucumber

• Others0 Fitnesse0 Tartare

BDD life cycle

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

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

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

BDD Life cycle

Run and watch it fail

BDD Life cycle Write code to make it pass:

BDD Life cycle

Run again and watch it pass:

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

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

BDD Life cycleWrite code to make it pass:

BDD Life cycle

Execute!

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 …

BDD Life cycleRefactor your scenarios and source code:

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.

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

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?

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 |

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

BDD life cycle

• Execute:

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

BDD life cycle

Execute:

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

BDD life cycle

BENEFITS

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

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!!!!

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

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

Questions?

Contact

Twiiter: @twiindan

Email: twiindan@gmail.com

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

Web: www.softqatest.com