SlideShare a Scribd company logo
S(p)exy testing in Coffeescript and Node.js




 Aaron Murray                Nicholas Vaidyanathan
 @WeAreFractal                   @SWVisionary
We’re glad you’re here!




But you obviously care about tests, so
 let’s talk about some terminology…
TDD, ATDD, BDD, DDD?
                          That’s a lot of DD’s

• TDD = Test Driven Development – Development Methodology, write tests
  first, test using xUnit – make sure the code works

• ATDD = Acceptance Test Driven Development – business-readable, Team-
  driven, tests owned by client – make sure the features are correct

• BDD = Behavior Driven Development – Team-driven, “Should”, “Given,
  When, Then” – extends TDD and incorporates ATDD

• DDD = Domain Driven Design – outlines the idea of the Ubiquitous
  Language used between non-technical stakeholders and developers
Wait, DDD? Why?
• What does DDD have to do with BDD?
• Proper architecture helps you
  – set up smallest possible services
  – Focus on nouns and verbs
  – Describes behavior, which drives BDD process
• Testing IS Design!!!!

• GOOD ARCHITECTURE IS PIVOTAL TO
  SUCCESSFUL BDD!
In the beginning, there was TDD
• Test Driven Development
  – Rediscovered by Kent Beck @kentbeck
• Simple Process
  – Test
  – Code
  – Refactor
Tests looked like this




• http://junit.sourceforge.net/doc/cookbook/cook
  book.htm
Then we came to ATDD
                      • TDD is a programming practice, not
                        a testing technique.
                      • Acceptance Test Driven
                        Development (ATDD) also involves
                        creating tests before code
                      • tests represent expectations of
                        behavior the software should have.
                      • team creates one or more
                        acceptance-level tests for a feature
                        before beginning work on it.
                      • team discusses tests and captures
                        them when working with the
                        business stakeholder(s) to
                        understand a story on the backlog.



• http://testobsessed.com/wp-
  content/uploads/2011/04/atddexample.pdf
And BDD
• Evolved out of established agile practices and is designed to
  make them more accessible and effective for teams new to
  agile software delivery.
• Premises
   –   Test method names should be sentences
   –   A simple sentence template keeps test methods focused
   –   An expressive test name is helpful when a test fails
   –   “Behaviour” is a more useful word than “test”
   –   Determine the next most important behaviour
   –   Requirements are behaviour,too
   –   BDD provides a “ubiquitous language” for analysis
   –   Acceptance criteria should be executable
• http://dannorth.net/introducing-bdd/
BDD Breakdown
Fundamentally Two Types of BDD Tools

Business-readable output
    –   Replacement/Extension for TDD at the Unit-testing level
    –   Artifacts owned by developers (code)
    –   Provides other stakeholders with reports after developers have done the work
    –   Gspec, Spock, EasyB


Business-readable input
    –   Based on Acceptance Testing – coarse-grained features
    –   Artifacts owned by client
    –   Stakeholder involvement before developers have done any work
    –   Cucumber, FitNesse


    Not exclusive – can and probably need to be combined
EasyB
                                   business-readable output

input                                                output
scenario "Two amounts with the same currencies are   2 scenarios executed successfully.
       added", {
  given "Two different amounts with the same              Story: money
       currencies", {
    money1 = new Money(12, "CHF")                         scenario Two amounts with the same
    money2 = new Money(14, "CHF")
                                                        currencies are added
                                                           given Two different amounts with
    expected = new Money(26, "CHF")                     the same currencies
  }                                                        when Add given amounts
  when "Add given amounts" , {                             then New amount is sum of two
    result = money1.add(money2)                         given ones
  }                                                       scenario Two amounts with different
  then "New amount is sum of two given ones", {         currencies are added
    result.equals(expected).shouldBe true                  given Two amounts with different
  }                                                     currencies
                                                           when Add given amounts
}
                                                           then Operation should fail
…
<<truncated>>
Step 1: write your feature
                        Addition.feature
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

 Scenario: Add two numbers
   Given I have entered <input_1> into the calculator
   And I have entered <input_2> into the calculator
   When I press <button>
   Then the result should be <output> on the screen

 Examples:
   | input_1   |   input_2   |   button   |   output   |
   | 20        |   30        |   add      |   50       |
   | 2         |   5         |   add      |   7        |
   | 0         |   40        |   add      |   40       |
Step 2: step definition
                     CalculatorSteps.groovy
this.metaClass.mixin(cuke4duke.GroovyDsl)

Before() {
    calc = new Calculator()
}

Given(~"I have entered (d+) into the calculator") { int n ->
    calc.push n
}

When(~"I press (w+)") {op ->
    result = calc.send(op)
}

Then(~"the result should be (.*) on the screen") { int r ->
    assert r == result
}
Step 4: write code to make it pass
                          Calculator.groovy
class Calculator {
    def numbers = []

    void push(number) {
        numbers << number
    }

    def send(operation) {
        def result
        switch (operation) {
            case "add":
                result = add()
        }
        numbers.clear()
        result
    }

    private def add() {
        numbers.sum()
    }
}
BDD in Java/Coffeescript and Node
• Best available frameworks
  – Jasmine
  – Vows
• Comparison
  – http://stackoverflow.com/questions/4115492/jav
    ascript-bdd-vows-kyuri-vs-jasmine
• So…
Introducing
•   Built in Node.js natively
•   Written in CoffeeScript
•   Modular, clean architecture
•   Designed to dramatically simplify the BDD process
•   Provides an annotation based mechanism for
    defining your tests
Example spec
Benefits
• Clean syntax
• Doesn’t pollute global namespace
• Flexibility

• Give it a try
   – https://github.com/wearefractal/spex
• LIVE DEMO

More Related Content

Similar to Bdd spex

Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
Frédéric Delorme
 
My Dad Won't Buy Me DevOps
My Dad Won't Buy Me DevOpsMy Dad Won't Buy Me DevOps
My Dad Won't Buy Me DevOps
XebiaLabs
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
Paul Chao
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
Daniel Kummer
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
Caleb Jenkins
 
ITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven DevelopmentITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven Development
Ortus Solutions, Corp
 
Rspec
RspecRspec
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!
XPDays
 
Test box bdd
Test box bddTest box bdd
Test box bdd
ColdFusionConference
 
CBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBoxCBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBox
Ortus Solutions, Corp
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
Qureshi Tehmina
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
Programming as a writing genre
Programming as a writing genreProgramming as a writing genre
Programming as a writing genre
Stephen Frezza
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
Kerry Buckley
 
Behavior-Driven Development with JGiven
Behavior-Driven Development with JGivenBehavior-Driven Development with JGiven
Behavior-Driven Development with JGiven
Haufe-Lexware GmbH & Co KG
 
Getting started with code composer studio v4 for tms320 f2812
Getting started with code composer studio v4 for tms320 f2812Getting started with code composer studio v4 for tms320 f2812
Getting started with code composer studio v4 for tms320 f2812
Pantech ProLabs India Pvt Ltd
 
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
Stowarzyszenie Jakości Systemów Informatycznych (SJSI)
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
Pavneet Singh Saund
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 

Similar to Bdd spex (20)

Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
 
My Dad Won't Buy Me DevOps
My Dad Won't Buy Me DevOpsMy Dad Won't Buy Me DevOps
My Dad Won't Buy Me DevOps
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
 
ITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven DevelopmentITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven Development
 
Rspec
RspecRspec
Rspec
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!
 
Test box bdd
Test box bddTest box bdd
Test box bdd
 
CBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBoxCBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBox
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Programming as a writing genre
Programming as a writing genreProgramming as a writing genre
Programming as a writing genre
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Behavior-Driven Development with JGiven
Behavior-Driven Development with JGivenBehavior-Driven Development with JGiven
Behavior-Driven Development with JGiven
 
Getting started with code composer studio v4 for tms320 f2812
Getting started with code composer studio v4 for tms320 f2812Getting started with code composer studio v4 for tms320 f2812
Getting started with code composer studio v4 for tms320 f2812
 
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 

Recently uploaded

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 

Recently uploaded (20)

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 

Bdd spex

  • 1. S(p)exy testing in Coffeescript and Node.js Aaron Murray Nicholas Vaidyanathan @WeAreFractal @SWVisionary
  • 2.
  • 3. We’re glad you’re here! But you obviously care about tests, so let’s talk about some terminology…
  • 4. TDD, ATDD, BDD, DDD? That’s a lot of DD’s • TDD = Test Driven Development – Development Methodology, write tests first, test using xUnit – make sure the code works • ATDD = Acceptance Test Driven Development – business-readable, Team- driven, tests owned by client – make sure the features are correct • BDD = Behavior Driven Development – Team-driven, “Should”, “Given, When, Then” – extends TDD and incorporates ATDD • DDD = Domain Driven Design – outlines the idea of the Ubiquitous Language used between non-technical stakeholders and developers
  • 5. Wait, DDD? Why? • What does DDD have to do with BDD? • Proper architecture helps you – set up smallest possible services – Focus on nouns and verbs – Describes behavior, which drives BDD process • Testing IS Design!!!! • GOOD ARCHITECTURE IS PIVOTAL TO SUCCESSFUL BDD!
  • 6. In the beginning, there was TDD • Test Driven Development – Rediscovered by Kent Beck @kentbeck • Simple Process – Test – Code – Refactor
  • 7. Tests looked like this • http://junit.sourceforge.net/doc/cookbook/cook book.htm
  • 8. Then we came to ATDD • TDD is a programming practice, not a testing technique. • Acceptance Test Driven Development (ATDD) also involves creating tests before code • tests represent expectations of behavior the software should have. • team creates one or more acceptance-level tests for a feature before beginning work on it. • team discusses tests and captures them when working with the business stakeholder(s) to understand a story on the backlog. • http://testobsessed.com/wp- content/uploads/2011/04/atddexample.pdf
  • 9. And BDD • Evolved out of established agile practices and is designed to make them more accessible and effective for teams new to agile software delivery. • Premises – Test method names should be sentences – A simple sentence template keeps test methods focused – An expressive test name is helpful when a test fails – “Behaviour” is a more useful word than “test” – Determine the next most important behaviour – Requirements are behaviour,too – BDD provides a “ubiquitous language” for analysis – Acceptance criteria should be executable • http://dannorth.net/introducing-bdd/
  • 10. BDD Breakdown Fundamentally Two Types of BDD Tools Business-readable output – Replacement/Extension for TDD at the Unit-testing level – Artifacts owned by developers (code) – Provides other stakeholders with reports after developers have done the work – Gspec, Spock, EasyB Business-readable input – Based on Acceptance Testing – coarse-grained features – Artifacts owned by client – Stakeholder involvement before developers have done any work – Cucumber, FitNesse Not exclusive – can and probably need to be combined
  • 11. EasyB business-readable output input output scenario "Two amounts with the same currencies are 2 scenarios executed successfully. added", { given "Two different amounts with the same Story: money currencies", { money1 = new Money(12, "CHF") scenario Two amounts with the same money2 = new Money(14, "CHF") currencies are added given Two different amounts with expected = new Money(26, "CHF") the same currencies } when Add given amounts when "Add given amounts" , { then New amount is sum of two result = money1.add(money2) given ones } scenario Two amounts with different then "New amount is sum of two given ones", { currencies are added result.equals(expected).shouldBe true given Two amounts with different } currencies when Add given amounts } then Operation should fail … <<truncated>>
  • 12. Step 1: write your feature Addition.feature Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers Scenario: Add two numbers Given I have entered <input_1> into the calculator And I have entered <input_2> into the calculator When I press <button> Then the result should be <output> on the screen Examples: | input_1 | input_2 | button | output | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
  • 13. Step 2: step definition CalculatorSteps.groovy this.metaClass.mixin(cuke4duke.GroovyDsl) Before() { calc = new Calculator() } Given(~"I have entered (d+) into the calculator") { int n -> calc.push n } When(~"I press (w+)") {op -> result = calc.send(op) } Then(~"the result should be (.*) on the screen") { int r -> assert r == result }
  • 14. Step 4: write code to make it pass Calculator.groovy class Calculator { def numbers = [] void push(number) { numbers << number } def send(operation) { def result switch (operation) { case "add": result = add() } numbers.clear() result } private def add() { numbers.sum() } }
  • 15. BDD in Java/Coffeescript and Node • Best available frameworks – Jasmine – Vows • Comparison – http://stackoverflow.com/questions/4115492/jav ascript-bdd-vows-kyuri-vs-jasmine • So…
  • 16. Introducing • Built in Node.js natively • Written in CoffeeScript • Modular, clean architecture • Designed to dramatically simplify the BDD process • Provides an annotation based mechanism for defining your tests
  • 18.
  • 19. Benefits • Clean syntax • Doesn’t pollute global namespace • Flexibility • Give it a try – https://github.com/wearefractal/spex • LIVE DEMO