BEHAVIOR DRIVEN
DEVELOPMENT
Ritesh Mehrotra
©TechTalks, 2018
References
• “BDD in action” by John Ferguson Smart
• “Specification by example” by Gojko Adzic
©TechTalks, 2018
Agenda
• What is BDD?
• How it differs from complementsTDD?
• Real examples onTDD/BDD
• Dive deeper into BDD
• Q & A
©TechTalks, 2018
The beginning
• Approach to collaboratively develop
software that delivers value and is
transparent
• Coined and developed by Dan north
• Meant to address limitations with
TDD
• Popular frameworks: Cucumber,
Specflow, Jasmine(BDD like),
Jbehave
• Expressed in Gherkin language
©TechTalks, 2018
Gherkin language
Feature: Knowledge sharing session
Narrative: As a speaker, I want to record my talk, so that I can replay it later for
audience who could not attend
Scenario: Recording a session
Given: I am a speaker in a session
And: I have placed a camera in the room
When: I start the recording
Then:The session should get recorded
©TechTalks, 2018
What isTDD?
• “Set of techniques that encourages
simple design and test suites that
inspire confidence” – Kent Beck
• Write a failing automated test before
code
• Remove duplication
©TechTalks, 2018
Write code
to pass the
test
Refactor code
without letting the
test fail
A failing
test without
code
WhyTDD?
• Improves the software design
• Enhances developer ability to write readable and easier-to-maintain code
• Helps set the boundaries of expected work - example
• Subsequently lesser defects
©TechTalks, 2018
So where is the problem?
©TechTalks, 2018
Persona #1
• Name: Max
• Age: 35
• Occupation: Software Professional
• BIO
Software developer and consultant. Has a family of 4
He has just moved to Singapore on employment visa with a multi-national
company. On induction, his employer, familiarized Max with the surroundings,
work culture and terms of employment contract.
Max is staying in a company sponsored hotel, and will need to rent a place within
a week’s time. He didn’t anticipate the expenses, and is carrying little cash. He
hopes he will be able to cover expenses with first salary due soon
The company pays all their employees at last day of the month through bank
transfers. He has joined in 3rd week of month, and needs a account soon to
receive his salary in time.
©TechTalks, 2018
Persona #2
• Name: Rob
• Age 50
• Occupation: Trader and Investor
• Bio
Rob is anTrader and investor with business interest in Asia-pacific region.
Primarily based in Singapore, he travels across China, Indonesia, Cambodia
and India very frequently for business.
He often employs vendors for his business and pays them through cheque
post work. Due to his busy schedule and frequent travels, the payments are
sometimes late and annoys the business partners.
To secure his and partners business interests, he needs a easier way of making
payments
©TechTalks, 2018
Features
In order to receive payments for my work,
As a prospective banking customer,
I want to open a savings bank account
©TechTalks, 2018
In order to make payments to contractors,
As a bank customer,
I want to initialize a funds transfer from my savings
account
Who?
What?
Why?
Story #1
©TechTalks, 2018
Title: Open a savings account
In order to receive payments for my work,
As a prospective banking customer,
I want to open a savings account
Acceptance criteria
©TechTalks, 2018
Inputs:
- Full name
- Unique identifier (NRIC, FIN, Passport)
- Address
- Email address
- Phone number
- Agreement onT&C
- AccountType: Savings
Output:
- Account number: 6 digit unique account number
- Account type: Savings
- Deposit funds
- Withdraw funds
- Statements
- Debit card
Story #2
©TechTalks, 2018
Title: Transfer funds from one account to another
In order to make payment to contractor,
As a bank customer,
I want to initialize a funds transfer from my savings account
Acceptance criteria
©TechTalks, 2018
Inputs:
- From account: 6 digit account number
- To account: 6 digit account number
- Amount: Decimal value greater than ZERO(0). Referred hereafter as $
Output:
- Transaction id: Numeric id
- From account debited of $(decimal value)
- To account credited of $(decimal value)
Let’s code
©TechTalks, 2018
The limitation withTDD
• What all to test? How much to test? What should we name it?
• How to validate that tests cover the acceptance criteria?
• Maintenance and readability a challenge as product grows in size
• Does it the right way. But does it do the right thing?
©TechTalks, 2018
BDD deep dive
©TechTalks, 2018
What is BDD again?
• BDD =TDD + Enhanced business collaboration
• Aligned to the business value
• A single source of truth – equally understood by business and development teams
©TechTalks, 2018
Whose behavior?
• Business
• Consumer
• Customers/Beneficiaries
• Staff
• Govt.Agencies/Regulatory/Audit
©TechTalks, 2018
What is value?
• Increase profit - Eg. New features
• Protect profit – Eg. Customer
satisfaction
• Reduce cost – Eg. Support
• Avoid future cost – Eg. Regulatory
©TechTalks, 2018
Where is value?
©TechTalks, 2018
IDENTIFYTHEVALUE
©TechTalks, 2018
(Why?) * 5
©TechTalks, 2018
RCA example
• The system is currently down
• Why?
• The underlying authentication service is failing so we cannot log in
• Why?
• The authentication service cannot connect to repository
• Why?
• The connection parameters are incorrect
• Why?
• There was a change in database host name which was not updated in authentication
service
©TechTalks, 2018
Applied to goal discovery
• We want to offer $ 25 cashback for customers who do less than 10 withdrawals a month?
• Why do you offer that?
• A promotion will encourage more customers to do lesser withdrawals
• Why do you want to encourage them?
• By means of that, we want to promote cashless transactions
• Why so?
• Because we want to reduce usage of ATM
• Why?
• Maintaining the ATMs is an additional cost, and our analysis suggests that we will be able
to save cost by 5% by reducing usage
©TechTalks, 2018
Impact mapping
©TechTalks, 2018
Why? Who? How? What?
Business Goal Stakeholders Capabilities Features
Save the cost by 5%
Enable cashless
transactions
Offer cashback on less
than 10 withdrawals
Pay online
Pay by card
Pay by cheque
Capture number of
transactions
Approach
©TechTalks, 2018
Seek example
• “Can you give me an example?”
• Precise specifications so delivery teams avoid rework caused by ambiguity
• Objective way to measure when work is complete
• Documentation to facilitate change, both in terms of features and team structure
• Described in book “Specification by Example” by Gojko Adzie
©TechTalks, 2018
Let’s revisit code
©TechTalks, 2018
BDD in a nutshell
©TechTalks, 2018
ThankYou!!
©TechTalks, 2018

Behavior driven development

  • 1.
  • 2.
    References • “BDD inaction” by John Ferguson Smart • “Specification by example” by Gojko Adzic ©TechTalks, 2018
  • 3.
    Agenda • What isBDD? • How it differs from complementsTDD? • Real examples onTDD/BDD • Dive deeper into BDD • Q & A ©TechTalks, 2018
  • 4.
    The beginning • Approachto collaboratively develop software that delivers value and is transparent • Coined and developed by Dan north • Meant to address limitations with TDD • Popular frameworks: Cucumber, Specflow, Jasmine(BDD like), Jbehave • Expressed in Gherkin language ©TechTalks, 2018
  • 5.
    Gherkin language Feature: Knowledgesharing session Narrative: As a speaker, I want to record my talk, so that I can replay it later for audience who could not attend Scenario: Recording a session Given: I am a speaker in a session And: I have placed a camera in the room When: I start the recording Then:The session should get recorded ©TechTalks, 2018
  • 6.
    What isTDD? • “Setof techniques that encourages simple design and test suites that inspire confidence” – Kent Beck • Write a failing automated test before code • Remove duplication ©TechTalks, 2018 Write code to pass the test Refactor code without letting the test fail A failing test without code
  • 7.
    WhyTDD? • Improves thesoftware design • Enhances developer ability to write readable and easier-to-maintain code • Helps set the boundaries of expected work - example • Subsequently lesser defects ©TechTalks, 2018
  • 8.
    So where isthe problem? ©TechTalks, 2018
  • 9.
    Persona #1 • Name:Max • Age: 35 • Occupation: Software Professional • BIO Software developer and consultant. Has a family of 4 He has just moved to Singapore on employment visa with a multi-national company. On induction, his employer, familiarized Max with the surroundings, work culture and terms of employment contract. Max is staying in a company sponsored hotel, and will need to rent a place within a week’s time. He didn’t anticipate the expenses, and is carrying little cash. He hopes he will be able to cover expenses with first salary due soon The company pays all their employees at last day of the month through bank transfers. He has joined in 3rd week of month, and needs a account soon to receive his salary in time. ©TechTalks, 2018
  • 10.
    Persona #2 • Name:Rob • Age 50 • Occupation: Trader and Investor • Bio Rob is anTrader and investor with business interest in Asia-pacific region. Primarily based in Singapore, he travels across China, Indonesia, Cambodia and India very frequently for business. He often employs vendors for his business and pays them through cheque post work. Due to his busy schedule and frequent travels, the payments are sometimes late and annoys the business partners. To secure his and partners business interests, he needs a easier way of making payments ©TechTalks, 2018
  • 11.
    Features In order toreceive payments for my work, As a prospective banking customer, I want to open a savings bank account ©TechTalks, 2018 In order to make payments to contractors, As a bank customer, I want to initialize a funds transfer from my savings account Who? What? Why?
  • 12.
    Story #1 ©TechTalks, 2018 Title:Open a savings account In order to receive payments for my work, As a prospective banking customer, I want to open a savings account
  • 13.
    Acceptance criteria ©TechTalks, 2018 Inputs: -Full name - Unique identifier (NRIC, FIN, Passport) - Address - Email address - Phone number - Agreement onT&C - AccountType: Savings Output: - Account number: 6 digit unique account number - Account type: Savings - Deposit funds - Withdraw funds - Statements - Debit card
  • 14.
    Story #2 ©TechTalks, 2018 Title:Transfer funds from one account to another In order to make payment to contractor, As a bank customer, I want to initialize a funds transfer from my savings account
  • 15.
    Acceptance criteria ©TechTalks, 2018 Inputs: -From account: 6 digit account number - To account: 6 digit account number - Amount: Decimal value greater than ZERO(0). Referred hereafter as $ Output: - Transaction id: Numeric id - From account debited of $(decimal value) - To account credited of $(decimal value)
  • 16.
  • 17.
    The limitation withTDD •What all to test? How much to test? What should we name it? • How to validate that tests cover the acceptance criteria? • Maintenance and readability a challenge as product grows in size • Does it the right way. But does it do the right thing? ©TechTalks, 2018
  • 18.
  • 19.
    What is BDDagain? • BDD =TDD + Enhanced business collaboration • Aligned to the business value • A single source of truth – equally understood by business and development teams ©TechTalks, 2018
  • 20.
    Whose behavior? • Business •Consumer • Customers/Beneficiaries • Staff • Govt.Agencies/Regulatory/Audit ©TechTalks, 2018
  • 21.
    What is value? •Increase profit - Eg. New features • Protect profit – Eg. Customer satisfaction • Reduce cost – Eg. Support • Avoid future cost – Eg. Regulatory ©TechTalks, 2018
  • 22.
  • 23.
  • 24.
  • 25.
    RCA example • Thesystem is currently down • Why? • The underlying authentication service is failing so we cannot log in • Why? • The authentication service cannot connect to repository • Why? • The connection parameters are incorrect • Why? • There was a change in database host name which was not updated in authentication service ©TechTalks, 2018
  • 26.
    Applied to goaldiscovery • We want to offer $ 25 cashback for customers who do less than 10 withdrawals a month? • Why do you offer that? • A promotion will encourage more customers to do lesser withdrawals • Why do you want to encourage them? • By means of that, we want to promote cashless transactions • Why so? • Because we want to reduce usage of ATM • Why? • Maintaining the ATMs is an additional cost, and our analysis suggests that we will be able to save cost by 5% by reducing usage ©TechTalks, 2018
  • 27.
    Impact mapping ©TechTalks, 2018 Why?Who? How? What? Business Goal Stakeholders Capabilities Features Save the cost by 5% Enable cashless transactions Offer cashback on less than 10 withdrawals Pay online Pay by card Pay by cheque Capture number of transactions
  • 28.
  • 29.
    Seek example • “Canyou give me an example?” • Precise specifications so delivery teams avoid rework caused by ambiguity • Objective way to measure when work is complete • Documentation to facilitate change, both in terms of features and team structure • Described in book “Specification by Example” by Gojko Adzie ©TechTalks, 2018
  • 30.
  • 31.
    BDD in anutshell ©TechTalks, 2018
  • 32.