SlideShare a Scribd company logo
1 of 21
describing your system
     one specification at a time
Pavneet Singh Saund

       m : pavneet@dolittle.com
       t : @pavsaund
       w : dolittle.com / blog.dolittle.com
       l : linkedin.com/in/pavneet
Unit testing
Test-Driven Development

• Accepted fact that we should test our code
• Tests should cover a single unit
• Each Unit should be driven out by a test (Test-Driven
  Development)

• TDD is meant to help drive out the architecture
... but
•   Where to start?

•   What to test?

•   What NOT to test?

•   How much to test?

•   How to name your tests?

•   Understanding why tests fail?
Behaviour Driven
  Development
What is BDD?

• Term coined by Dan North
• A reaction to confusions and misunderstandings about
  Test-Driven Development and how it fits in agile
  processes

• An approach to software development that aids to
  focus on delivering business value by focus on
  behaviour
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.

                                                      - Dan North 2009
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.




 •   Based on ideas from :

     •   Extreme Programming

     •   Lean Software development

     •   Domain Driven Design
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.




 •   Focusing on specifications that describe the output of the system

 •   Specifications created Just-in-time and pulled in
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.




 •   Not only just a “user”

 •   Focus on groups of people that are affected by the system

 •   ex: end-users, business stakeholders, IT-Operations, other developers..

 •   Defining and using a ubiquitous language for each groups concerns
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.




 •   Specifications can be described at multiple levels

     •   Top-level can focus on user-interaction

     •   Further down can focus on affected areas that fulfill the higher levels
         expectations

     •   Even lower we can focus on technical implementation, still with a solid
         focus on the behaviour
Specification by example
What is BDD?

• A different way to drive our design (tests)
• Replacing tests with specifications that describe the
  behaviour of our system

• “Given When Then” - popularized by Gherkin
• Heavy usage of Mocking to abstract away details
GWT

Given_a_series_of_conditions   //Arrange

When_I_do_something              //Act

Then_something_should_happen   //Assert
MSpec
 • Context/Specification framework
 • Uses keywords:
Establish context = () =>
Because of = () =>
It should = () >
  • Fluent assertions : myresult.ShouldEqual(expected_result)
  • You have to accept the lambda syntax! :)
MSpec practices
•   “Because of = () => “ should only be one line

•   “It_should.. = ()=>” should only contain a single assertion

•   Re-use contexts by using multiple level of base classes that each have their own
    “Establish context = () =>”

•   Be consistent with lower_case_naming_of_variables_and_classes - this aids readability

•   [Subject()] attribute adds an extra layer of context when “reading” specification ouput
    in ex. TestDriven.net

•   Can also group behaviours with Behaves_like<> to remove duplicated assertions
Typical unit test
Typical mspec specification
DEMO




beware of bugs
Resources
•   MSpec - https://github.com/machine/machine.specifications

•   MSpec with Resharper - https://github.com/machine/machine.specifications#resharper

•   Context / Specification - http://www.code-magazine.com/article.aspx?quickid=0805061

•   http://en.wikipedia.org/wiki/Behavior-driven_development

•   http://dannorth.net/introducing-bdd/

•   http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/

•   Chirp - Bifrost Sample application with MSpec scenarios http://chirp.dolittle.com /
    https://github.com/dolittle/chirp/

More Related Content

What's hot

TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereDaniel Davis
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentMike Douglas
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecBen Mabey
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NETdanhermes
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in PracticeSteven Mak
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
DDT Testing Library for Android
DDT Testing Library for AndroidDDT Testing Library for Android
DDT Testing Library for AndroidAhmed Misbah
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
Unit testing
Unit testingUnit testing
Unit testingAdam Birr
 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
 
(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should knowRichard Cheng
 
Design For Testability
Design For TestabilityDesign For Testability
Design For TestabilityWill Iverson
 
Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Ajay Danait
 
ISTQB agile tester exam - Conclusions about Certification
ISTQB agile tester exam - Conclusions about CertificationISTQB agile tester exam - Conclusions about Certification
ISTQB agile tester exam - Conclusions about CertificationMichał Dudziak
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentMireia Sangalo
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 

What's hot (20)

TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & Where
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in Practice
 
Journey of atdd
Journey of atddJourney of atdd
Journey of atdd
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
DDT Testing Library for Android
DDT Testing Library for AndroidDDT Testing Library for Android
DDT Testing Library for Android
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Unit testing
Unit testingUnit testing
Unit testing
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know
 
Design For Testability
Design For TestabilityDesign For Testability
Design For Testability
 
Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Behavior Driven Development (BDD)
Behavior Driven Development (BDD)
 
ISTQB agile tester exam - Conclusions about Certification
ISTQB agile tester exam - Conclusions about CertificationISTQB agile tester exam - Conclusions about Certification
ISTQB agile tester exam - Conclusions about Certification
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Testing & Scrum
Testing & ScrumTesting & Scrum
Testing & Scrum
 
Atdd half day_new_1_up
Atdd half day_new_1_upAtdd half day_new_1_up
Atdd half day_new_1_up
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 

Viewers also liked

Viewers also liked (7)

Forseti driven javascript
Forseti driven javascriptForseti driven javascript
Forseti driven javascript
 
Dot Net Notts Js Unit Testing at Microlise
Dot Net Notts Js Unit Testing at  MicroliseDot Net Notts Js Unit Testing at  Microlise
Dot Net Notts Js Unit Testing at Microlise
 
Fleet Management Telematics Devices
Fleet Management Telematics DevicesFleet Management Telematics Devices
Fleet Management Telematics Devices
 
Making komplett big by going small
Making komplett big by going smallMaking komplett big by going small
Making komplett big by going small
 
Telematics for Fleet Management
Telematics for Fleet ManagementTelematics for Fleet Management
Telematics for Fleet Management
 
M2M Telefónica - Internet of Things Keynote
M2M Telefónica - Internet of Things KeynoteM2M Telefónica - Internet of Things Keynote
M2M Telefónica - Internet of Things Keynote
 
Transportation Management Ppt
Transportation Management PptTransportation Management Ppt
Transportation Management Ppt
 

Similar to Unit testing and BDD with MSpec

Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanQA or the Highway
 
Prashant technical practices-tdd for xebia event
Prashant   technical practices-tdd for xebia eventPrashant   technical practices-tdd for xebia event
Prashant technical practices-tdd for xebia eventXebia India
 
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...Microservices at Scale: How to Reduce Overhead and Increase Developer Product...
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...DevOps.com
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Agility via Software Engineering Practices - Agile Tour Montreal 2015
Agility via Software Engineering Practices - Agile Tour Montreal 2015Agility via Software Engineering Practices - Agile Tour Montreal 2015
Agility via Software Engineering Practices - Agile Tour Montreal 2015Steve Mercier
 
Agile Development unleashed
Agile Development unleashedAgile Development unleashed
Agile Development unleashedlivgeni
 
Making software development processes to work for you
Making software development processes to work for youMaking software development processes to work for you
Making software development processes to work for youAmbientia
 
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems SoftwareLessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems SoftwareDevOps for Enterprise Systems
 
Approaching ATDD/BDD
Approaching ATDD/BDDApproaching ATDD/BDD
Approaching ATDD/BDDDhaval Dalal
 
Preparing for DevOps
Preparing for DevOpsPreparing for DevOps
Preparing for DevOpsEklove Mohan
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
"X" Driven-Development Methodologies
"X" Driven-Development Methodologies"X" Driven-Development Methodologies
"X" Driven-Development MethodologiesDamian T. Gordon
 
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719BingWang77
 
Dev ops != Dev+Ops
Dev ops != Dev+OpsDev ops != Dev+Ops
Dev ops != Dev+OpsShalu Ahuja
 
DevOps Roadshow - removing barriers between development and operations
DevOps Roadshow - removing barriers between development and operationsDevOps Roadshow - removing barriers between development and operations
DevOps Roadshow - removing barriers between development and operationsMicrosoft Developer Norway
 

Similar to Unit testing and BDD with MSpec (20)

Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
 
Prashant technical practices-tdd for xebia event
Prashant   technical practices-tdd for xebia eventPrashant   technical practices-tdd for xebia event
Prashant technical practices-tdd for xebia event
 
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...Microservices at Scale: How to Reduce Overhead and Increase Developer Product...
Microservices at Scale: How to Reduce Overhead and Increase Developer Product...
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Agility via Software Engineering Practices - Agile Tour Montreal 2015
Agility via Software Engineering Practices - Agile Tour Montreal 2015Agility via Software Engineering Practices - Agile Tour Montreal 2015
Agility via Software Engineering Practices - Agile Tour Montreal 2015
 
Agile Development unleashed
Agile Development unleashedAgile Development unleashed
Agile Development unleashed
 
Making software development processes to work for you
Making software development processes to work for youMaking software development processes to work for you
Making software development processes to work for you
 
Agile testing
Agile testingAgile testing
Agile testing
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems SoftwareLessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
 
Approaching ATDD/BDD
Approaching ATDD/BDDApproaching ATDD/BDD
Approaching ATDD/BDD
 
Preparing for DevOps
Preparing for DevOpsPreparing for DevOps
Preparing for DevOps
 
Test box bdd
Test box bddTest box bdd
Test box bdd
 
OOSE UNIT-1.pdf
OOSE UNIT-1.pdfOOSE UNIT-1.pdf
OOSE UNIT-1.pdf
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
"X" Driven-Development Methodologies
"X" Driven-Development Methodologies"X" Driven-Development Methodologies
"X" Driven-Development Methodologies
 
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
 
Dev ops != Dev+Ops
Dev ops != Dev+OpsDev ops != Dev+Ops
Dev ops != Dev+Ops
 
DevOps Roadshow - removing barriers between development and operations
DevOps Roadshow - removing barriers between development and operationsDevOps Roadshow - removing barriers between development and operations
DevOps Roadshow - removing barriers between development and operations
 

Unit testing and BDD with MSpec

  • 1. describing your system one specification at a time
  • 2. Pavneet Singh Saund m : pavneet@dolittle.com t : @pavsaund w : dolittle.com / blog.dolittle.com l : linkedin.com/in/pavneet
  • 4. Test-Driven Development • Accepted fact that we should test our code • Tests should cover a single unit • Each Unit should be driven out by a test (Test-Driven Development) • TDD is meant to help drive out the architecture
  • 5. ... but • Where to start? • What to test? • What NOT to test? • How much to test? • How to name your tests? • Understanding why tests fail?
  • 6. Behaviour Driven Development
  • 7. What is BDD? • Term coined by Dan North • A reaction to confusions and misunderstandings about Test-Driven Development and how it fits in agile processes • An approach to software development that aids to focus on delivering business value by focus on behaviour
  • 8. 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. - Dan North 2009
  • 9. 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. • Based on ideas from : • Extreme Programming • Lean Software development • Domain Driven Design
  • 10. 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. • Focusing on specifications that describe the output of the system • Specifications created Just-in-time and pulled in
  • 11. 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. • Not only just a “user” • Focus on groups of people that are affected by the system • ex: end-users, business stakeholders, IT-Operations, other developers.. • Defining and using a ubiquitous language for each groups concerns
  • 12. 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. • Specifications can be described at multiple levels • Top-level can focus on user-interaction • Further down can focus on affected areas that fulfill the higher levels expectations • Even lower we can focus on technical implementation, still with a solid focus on the behaviour
  • 14. What is BDD? • A different way to drive our design (tests) • Replacing tests with specifications that describe the behaviour of our system • “Given When Then” - popularized by Gherkin • Heavy usage of Mocking to abstract away details
  • 15. GWT Given_a_series_of_conditions //Arrange When_I_do_something //Act Then_something_should_happen //Assert
  • 16. MSpec • Context/Specification framework • Uses keywords: Establish context = () => Because of = () => It should = () > • Fluent assertions : myresult.ShouldEqual(expected_result) • You have to accept the lambda syntax! :)
  • 17. MSpec practices • “Because of = () => “ should only be one line • “It_should.. = ()=>” should only contain a single assertion • Re-use contexts by using multiple level of base classes that each have their own “Establish context = () =>” • Be consistent with lower_case_naming_of_variables_and_classes - this aids readability • [Subject()] attribute adds an extra layer of context when “reading” specification ouput in ex. TestDriven.net • Can also group behaviours with Behaves_like<> to remove duplicated assertions
  • 21. Resources • MSpec - https://github.com/machine/machine.specifications • MSpec with Resharper - https://github.com/machine/machine.specifications#resharper • Context / Specification - http://www.code-magazine.com/article.aspx?quickid=0805061 • http://en.wikipedia.org/wiki/Behavior-driven_development • http://dannorth.net/introducing-bdd/ • http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/ • Chirp - Bifrost Sample application with MSpec scenarios http://chirp.dolittle.com / https://github.com/dolittle/chirp/