development (bdd) behavior driven · cucumber bdd framework feature files translation into code...

27
Behavior Driven Development (BDD) Pavel Rabetski

Upload: others

Post on 01-Oct-2020

41 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Behavior Driven Development (BDD)

Pavel Rabetski

Page 2: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Volvo Group Telematics

Page 3: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Agenda

● Introduction to BDD● Cucumber BDD framework● Live demo● Pros/cons of BDD● Questions?

Page 4: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Page 5: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Test Driven Development

Dan North

Page 6: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Page 7: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

MoneyWithdraw- success when enough money on account- fails when lack of money on account

agiledox >

Page 8: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Test Driven DevelopmentBehavior

Page 9: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

I want ... function X(){ return Y;}

If I click this button then ...

Tester

DeveloperBA

Page 10: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Page 11: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Ubiquitous requirements description

Documentation

Application code

Test scripts

Introduction to BDD

Tester

DeveloperBA

Page 12: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Page 13: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDD

Behavior Driven Development(how we write and test code)(how we write and test requirements)

Page 14: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDDStory (feature):

As a [role] I want [feature] so that [benefit]

Example: As a customer I want to withdraw money from an ATM so that I don’t have to go to the bank

Page 15: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Introduction to BDDStory acceptance criteria (scenario):

Given [initial context] when [event] then [outcomes]

Example: Given there is enough money on my account when I make a withdrawal then I get the expected amount of money from the ATM

Page 16: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Cucumber BDD framework

Page 17: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Cucumber BDD framework

Feature files

Translation into code

Cucumber Test scripts

Test runner (JUnit)

SUT

Page 18: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Cucumber: Gherkin logic

Feature: Withdraw money In order to avoid going to the bank As a customer I want to withdraw money from an ATM Scenario: Withdraw less money than the account has Given there is enough money on my account

When I make a withdrawal Then I get the expected amount of money from the ATMAnd receipt is printed

Gherkin logic

Page 19: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Cucumber: parametrization

Scenario: Withdraw less money ... Given I have 200 SEK on my account

When I withdraw 100 SEK Then I get 100 SEK from the ATM

Scenario: Withdraw more money ... Given I have 50 SEK on my account

When I withdraw 100 SEK Then I get 0 SEK from the ATM

Gherkin logic Scenario: Withdraw money from the account Given I have <balance> SEK on my account

When I withdraw <withdraw> SEK Then I get <received> SEK from the ATM

Examples:

| balance| withdraw | received || 200 | 100 | 100 || 50 | 100 | 0 |

Page 20: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Cucumber: annotations

@prod Scenario: Withdraw less money ... Given I have 200 SEK on my account

When I withdraw 100 SEK Then I get 100 SEK from the ATM

@test Scenario: Withdraw more money ... Given I have 50 SEK on my account

When I withdraw 100 SEK Then I get 0 SEK from the ATM

Gherkin logic

Page 21: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

BDD for complex systems

Page 22: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Live demo: OEM portal

Page 23: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Live demo: ATM

Page 24: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Pros/cons of BDD

● Level of abstraction for steps?● Becomes complex for complex systems● Lack of tool support

Page 25: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

P.S. BDD in a context of FSMGiven I have 200 SEK on my account when I withdraw 100 SEK then I get 100 SEK from the ATM

Page 26: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

Questions?

Page 27: Development (BDD) Behavior Driven · Cucumber BDD framework Feature files Translation into code Cucumber Test scripts Test runner (JUnit) SUT. Cucumber: Gherkin logic Feature: Withdraw

ReferencesCucumber framework:https://cucumber.io/Gherkin language:http://docs.behat.org/en/latest/guides/1.gherkin.html

Dan North about BDD:http://dannorth.net/introducing-bdd/How BDD can be misused:https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool