Bdd training - v3

112
Behavior Driven Development & Specification by Example dimanche 22 septembre 13

description

BDD training v3 slides

Transcript of Bdd training - v3

Page 1: Bdd training - v3

Behavior Driven Development

&

Specification by Example

dimanche 22 septembre 13

Page 2: Bdd training - v3

TestersDevelopers

Domain Expert

dimanche 22 septembre 13

Page 3: Bdd training - v3

dimanche 22 septembre 13

Page 4: Bdd training - v3

dimanche 22 septembre 13

Page 5: Bdd training - v3

dimanche 22 septembre 13

Page 6: Bdd training - v3

dimanche 22 septembre 13

Page 7: Bdd training - v3

Softwaredevelopment

Steps

dimanche 22 septembre 13

Page 8: Bdd training - v3

Stakeholders define

objectives

dimanche 22 septembre 13

Page 9: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

dimanche 22 septembre 13

Page 10: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

dimanche 22 septembre 13

Page 11: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Testers (Quality Assurance)write requirements

test plan

dimanche 22 septembre 13

Page 12: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Testers (Quality Assurance)write requirements

test plan

dimanche 22 septembre 13

Page 13: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

dimanche 22 septembre 13

Page 14: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

dimanche 22 septembre 13

Page 15: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

dimanche 22 septembre 13

Page 16: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

defects

defectsdefects

defectsdefects

defects

defects

dimanche 22 septembre 13

Page 17: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

defects

defectsdefects

defectsdefects

defects

defects

defects

defectsdefects

defects

defects

dimanche 22 septembre 13

Page 18: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

defects

defectsdefects

defectsdefects

defects

defects

defects

defectsdefects

defects

defectsdefects

defects

defects defects

dimanche 22 septembre 13

Page 19: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

defects

defectsdefects

defectsdefects

defects

defects

defects

defectsdefects

defects

defectsdefects

defects

defects defectsdefects

defects

defects

defectsdefec

ts

defec

ts

defects

defect

s

defects

defects

dimanche 22 septembre 13

Page 20: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Pfiouuuu

dimanche 22 septembre 13

Page 21: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

dimanche 22 septembre 13

Page 22: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

dimanche 22 septembre 13

Page 23: Bdd training - v3

That is not what I want!

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

dimanche 22 septembre 13

Page 24: Bdd training - v3

Sourcesof

Errors/Bugs

dimanche 22 septembre 13

Page 25: Bdd training - v3

Sourcesof

Errors/Bugs

Misunderstandings

dimanche 22 septembre 13

Page 26: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

dimanche 22 septembre 13

Page 27: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

unable to define what they want

dimanche 22 septembre 13

Page 28: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

unable to define what they wantdon't know what they really want "now"

dimanche 22 septembre 13

Page 29: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

misunderstood the stakeholderswrong, incomplete or ambiguous requirements

dimanche 22 septembre 13

Page 30: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

misinterpret requirements

dimanche 22 septembre 13

Page 31: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

incomplete tests based on implementation not behavior

dimanche 22 septembre 13

Page 32: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

misinterpret requirements

dimanche 22 septembre 13

Page 33: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

"false positives" or "beatures"misinterpretation of application behavior

dimanche 22 septembre 13

Page 34: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

At least "6" Sources of Errors

dimanche 22 septembre 13

Page 35: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

At least "6" Sources of Errors

ops issues during deployment

dimanche 22 septembre 13

Page 36: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

Stakeholder

Domain Experts

Testers

Developers

dimanche 22 septembre 13

Page 37: Bdd training - v3

Stakeholders define

objectives

Business Requirements are defined

Functional and TechnicalRequirements are defined

Developers design and interpret

specification into code

Developers write

implementation tests

Testers (Quality Assurance)write requirements

test plan

Applicationis tested

Applicationis deployed in Production

Users use the

Application

At least "6" Sources of Errorsamong "4" different Roles

dimanche 22 septembre 13

Page 38: Bdd training - v3

StakeholderEnd-users

Domain Experts

Testers

Developers

dimanche 22 septembre 13

Page 39: Bdd training - v3

dimanche 22 septembre 13

Page 40: Bdd training - v3

dimanche 22 septembre 13

Page 41: Bdd training - v3

Discuss

Together

As a whole team!dimanche 22 septembre 13

Page 42: Bdd training - v3

dimanche 22 septembre 13

Page 43: Bdd training - v3

dimanche 22 septembre 13

Page 44: Bdd training - v3

dimanche 22 septembre 13

Page 45: Bdd training - v3

dimanche 22 septembre 13

Page 46: Bdd training - v3

dimanche 22 septembre 13

Page 47: Bdd training - v3

dimanche 22 septembre 13

Page 48: Bdd training - v3

dimanche 22 septembre 13

Page 49: Bdd training - v3

dimanche 22 septembre 13

Page 50: Bdd training - v3

dimanche 22 septembre 13

Page 51: Bdd training - v3

No Narrative No Business Value

Unnecessary Feature !

dimanche 22 septembre 13

Page 52: Bdd training - v3

dimanche 22 septembre 13

Page 53: Bdd training - v3

dimanche 22 septembre 13

Page 54: Bdd training - v3

dimanche 22 septembre 13

Page 55: Bdd training - v3

dimanche 22 septembre 13

Page 56: Bdd training - v3

Feature: Account Holder withdraws cash

As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed

dimanche 22 septembre 13

Page 57: Bdd training - v3

Scenario: Account has sufficient funds Given the account balance is 100€ And the card is valid And the machine contains enough money When the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned

dimanche 22 septembre 13

Page 58: Bdd training - v3

Scenario: The ATM has insufficient funds Given the account balance is 100€ And the card is valid And the machine contains only 20€ When the Account Holder requests 30€ Then the ATM should say it has insufficient funds And the account balance should be 100€ And the card should be returned

dimanche 22 septembre 13

Page 59: Bdd training - v3

dimanche 22 septembre 13

Page 60: Bdd training - v3

Scenario: Account has insufficient funds Given the account balance is 10€ And the card is valid And the machine contains enough money When the Account Holder requests 30€ Then the ATM should not dispense any money And the ATM should say there are insufficient funds And the account balance should still be 10€ And the card should be returned

dimanche 22 septembre 13

Page 61: Bdd training - v3

dimanche 22 septembre 13

Page 62: Bdd training - v3

dimanche 22 septembre 13

Page 63: Bdd training - v3

Scenario: Wrong PIN Given the card is valid And its PIN number is "0000" When the Account Holder enters "1234" Then the ATM should say the PIN number is wrong

dimanche 22 septembre 13

Page 64: Bdd training - v3

Scenario: Wrong PIN three times Given the card is valid And its PIN number is "0000" When the Account Holder enters "1234" And the Account Holder enters "4321" And the Account Holder enters "2341" Then the ATM should retain the card And the ATM should say the card has been retained

dimanche 22 septembre 13

Page 65: Bdd training - v3

Scenario: Card has been disabled Given the card is disabled When the Account Holder requests 30€ Then the ATM should retain the card And the ATM should say the card has been retained

dimanche 22 septembre 13

Page 66: Bdd training - v3

Scenario: Card has been disabled Given the card is disabled When the Account Holder requests 30€ Then the ATM should retain the card And the ATM should say the card has been retained

dimanche 22 septembre 13

Page 67: Bdd training - v3

dimanche 22 septembre 13

Page 68: Bdd training - v3

Feature: Interpolate

In order to interpolate values As an Trader I want to interpolate values in a range of Market data

Why this feature ?

dimanche 22 septembre 13

Page 69: Bdd training - v3

Feature: Interpolate

In order to interpolate values As an Trader I want to interpolate values in a range of Market data

Why this feature ?

dimanche 22 septembre 13

Page 70: Bdd training - v3

Feature: Linear Interpolation In order to fill the gaps and provide a value for any

maturity As a trader responsible for market-marking I want to interpolate linearly values within a range of

points And I want a flat extrapolation outside of the range of

points

Why this feature ?

dimanche 22 septembre 13

Page 71: Bdd training - v3

Scenario: Change the negotiation price from positive to negative => soulte cashflow appears and premium cashflow is modified

Given an FUNKY_EXOTIC And deal way is sell And deal nature is TOMATO And trade value date is 2012/07/01 And nominal is 100 JPYAnd negotiation price is 0.20 JPY When I validate the deal Then there are 1 Price cashflows And there are 0 fee cashflows When I change the negotiation price to -0.3 JPY And I validate the dealThen there are 1 Price cashflows And there are 1 fee cashflows And the trade cashflow's payment date is 2012/07/01 And the trade cashflow's way is receive And the trade cashflow's amount is 30 JPY And the fee cashflow's payment date is 2012/07/01 And the fee cashflow's way is give And the fee cashflow's amount is 60 JPY

What about this scenario

dimanche 22 septembre 13

Page 72: Bdd training - v3

Scenario: Change the negotiation price from positive to negative => soulte cashflow appears and premium cashflow is modified

Given an FUNKY_EXOTIC And deal way is sell And deal nature is TOMATO And trade value date is 2012/07/01 And nominal is 100 JPYAnd negotiation price is 0.20 JPY When I validate the deal Then there are 1 Price cashflows And there are 0 fee cashflows When I change the negotiation price to -0.3 JPY And I validate the dealThen there are 1 Price cashflows And there are 1 fee cashflows And the trade cashflow's payment date is 2012/07/01 And the trade cashflow's way is receive And the trade cashflow's amount is 30 JPY And the fee cashflow's payment date is 2012/07/01 And the fee cashflow's way is give And the fee cashflow's amount is 60 JPY

What about this scenario

d = new Deal(); d.SetWay(Sell); d.SetNature(Tomato); d.SetValueDate(new Date(...)); d.SetNominal(100, JPY); d.SetNegotiationPrice(0.20, JPY);cf = d.GetCashFlows(); AssertThat(IsEqual(...); ...

dimanche 22 septembre 13

Page 73: Bdd training - v3

Scenario: Fee and Price cashflows when the negotiation price is set to a negative value

Given a sell for a nominal 100 JPY on FUNKY_EXOTIC TOMATO negotiation price 0.20 JPY traded on 2012/07/01

When the middle officer validates the deal

Then the trade has one Price cashflow and no Fee cashflow

When the middle officer changes the negotiation price to -0.3 JPY

And the middle officer validates the deal

Then the trade has the following cashflows:

| FlowType| Way | Amount | Currency | PaymentDate | Remarks |

| Price | Receive| 30 | JPY | 2012/07/01 | 100*abs(-0.3) || Fee | Give | 60 | JPY | 2012/07/01 | 100*2*abs(-0.3)|

What about this scenario

Communicate With the Business People !!!

dimanche 22 septembre 13

Page 74: Bdd training - v3

dimanche 22 septembre 13

Page 75: Bdd training - v3

dimanche 22 septembre 13

Page 76: Bdd training - v3

dimanche 22 septembre 13

Page 77: Bdd training - v3

ScenarioBD

D FR

AMEW

ORK

GLUE

COD

E

Application

http://dribbble.com/shots/685089-The-Noun-Project-Bridge

bridging the gap between scenario and app.

dimanche 22 septembre 13

Page 78: Bdd training - v3

GLUE

COD

E

BDD

FRAM

EWOR

KSCENARIO

APPLICATION

SCEN

ARIO

dimanche 22 septembre 13

Page 79: Bdd training - v3

Scenario: Account has sufficient funds Given the account balance is 100€ When the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned

SCENARIO

APPLICATION

GLUE

COD

E

BDD

FRAM

EWOR

K

dimanche 22 septembre 13

Page 80: Bdd training - v3

Scenario: Account has sufficient funds Given the account balance is 100€ When the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned

SCENARIO

APPLICATION

GLUE

COD

E

BDD

FRAM

EWOR

K

dimanche 22 septembre 13

Page 81: Bdd training - v3

Scenario: Account has sufficient funds Given the account balance is 100€ When the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned

SCENARIO

@Given("^the account balance is (\d+)€$")public void defineAccountBalanceInEuro(BigDecimal balance) { throw new PendingException("Implements me!");}

@When("^the Account Holder request (\d+)€$")public void withdrawInEuro (BigDecimal amount) { throw new PendingException("Implements me!");}

@Then("^the ATM should dispense (\d+)€$")public void assertMoneyDispensedInEuro (BigDecimal amount) { throw new PendingException("Implements me!");}

@Then("^the account balance should be (\d+)€$")public void assertBalanceInEuro(BigDecimal amount) { throw new PendingException("Implements me!");}

GLUE CODE

APPL

ICAT

ION

BDD

FRAM

EWOR

K

dimanche 22 septembre 13

Page 82: Bdd training - v3

APPLICATION@Given("^the account balance is (\d+)€$")public void defineAccountBalanceInEuro(BigDecimal balance) { account().setBalance(euro(balance));}

@When("^the Account Holder request (\d+)€$")public void withdrawInEuro (BigDecimal amount) { atm().withdraw(account(), euro(amount));}

@Then("^the ATM should dispense (\d+)€$")public void assertMoneyDispensedInEuro (BigDecimal amount) { TransactionLog txLog = atm().transactionLog(); Money dispensed = txLog.lastAmountDispensed(); assertThat(dispensed).isEqualTo(euro(amount));}

@Then("^the account balance should be (\d+)€$")public void assertBalanceInEuro(BigDecimal amount) { Money actualBalance = account().balance(); assertThat(actualBalance).isEqualTo(euro(amount));}

GLUE CODE

APPL

ICAT

ION

Scenario: Account has sufficient funds Given the account balance is 100€ When the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned

SCENARIOBD

D FR

AMEW

ORK

dimanche 22 septembre 13

Page 83: Bdd training - v3

BDD

FRAM

EWOR

K

SCEN

ARIO

APPLICATIONGL

UE C

ODE

dimanche 22 septembre 13

Page 84: Bdd training - v3

dimanche 22 septembre 13

Page 85: Bdd training - v3

dimanche 22 septembre 13

Page 86: Bdd training - v3

dimanche 22 septembre 13

Page 87: Bdd training - v3

dimanche 22 septembre 13

Page 88: Bdd training - v3

dimanche 22 septembre 13

Page 89: Bdd training - v3

dimanche 22 septembre 13

Page 90: Bdd training - v3

dimanche 22 septembre 13

Page 91: Bdd training - v3

dimanche 22 septembre 13

Page 92: Bdd training - v3

dimanche 22 septembre 13

Page 93: Bdd training - v3

dimanche 22 septembre 13

Page 94: Bdd training - v3

dimanche 22 septembre 13

Page 95: Bdd training - v3

dimanche 22 septembre 13

Page 96: Bdd training - v3

dimanche 22 septembre 13

Page 97: Bdd training - v3

dimanche 22 septembre 13

Page 98: Bdd training - v3

dimanche 22 septembre 13

Page 99: Bdd training - v3

dimanche 22 septembre 13

Page 100: Bdd training - v3

dimanche 22 septembre 13

Page 101: Bdd training - v3

dimanche 22 septembre 13

Page 102: Bdd training - v3

dimanche 22 septembre 13

Page 103: Bdd training - v3

dimanche 22 septembre 13

Page 104: Bdd training - v3

You will learn to think of automated tests as executable specification that become living documentation – Mary Poppendieck

dimanche 22 septembre 13

Page 105: Bdd training - v3

dimanche 22 septembre 13

Page 106: Bdd training - v3

dimanche 22 septembre 13

Page 107: Bdd training - v3

dimanche 22 septembre 13

Page 108: Bdd training - v3

dimanche 22 septembre 13

Page 109: Bdd training - v3

dimanche 22 septembre 13

Page 110: Bdd training - v3

dimanche 22 septembre 13

Page 111: Bdd training - v3

dimanche 22 septembre 13

Page 112: Bdd training - v3

dimanche 22 septembre 13