SlideShare a Scribd company logo
1 of 13
Test Driven Development

•   What’s that?
•   The good…
•   The bad…
•   And the ugly…
•   How do we begin?
•   How do we make it sustainable?
•   Food for thought
What’s that?
1. Write a failing test
2. Get it to compile.
3. Make it pass (do not
change existing code).
4. Refactor to remove
duplication.
5. Repeat.
The good…
•   Edit and pray vs. Cover and Modify
•   Feedback, feedback, feedback!
•   Get a living Documentation
•   You have nothing to lose but your bugs!
•   Helps you design on the go
•   Makes ownership transfer much easier
•   Gives you more confidence in making changes
    to the code
The good…
• It’s highly likely that the code you write will:
   – Do what it’s meant to do!
   – Keep methods short & simple
   – Keep dependencies as weak as possible
   – Go 100% for Single Responsibility
   – Not have duplicates
   – Be protected from invalid input
   – Have many other qualities that make it awesome
     
The bad…
• You have to break some habits
• You’ll have some development time overhead
• You need to keep the test code as clean as the
  production code
• You still need the high level designs
• You still need more testing
And the ugly…
• TDD is only good when it’s done properly
• Coding Ain’t Done ‘Til All the Tests Run*…
  AND pass!
Is it worth it?!
• 100k lines of code => 15 issues 6 months after
  the release
• There’s no bug-free product, but there are
  collateral issues safe nets.
How do we begin?
1. Understand the problem
2. High-level architecture
3. Ensure automation for:
     –   Writing tests
     –   Building
     –   Running Tests
4.   Write a failing acceptance test = walking skeleton 
5.   Write a failing unit test
6.   Make the unit test pass
7.   Refactor
8.   Repeat Steps 5-7 until you make the acceptance test pass
9.   Repeat Steps 4-8 until all the acceptance tests pass.
Automation tools
• Tests Explorer (VS2012)
• MSUnit
  – As simple as “Create New Project”
  – Generate methods from Unit Tests (VS2012)
• Microsoft Fakes
• Code Coverage Tools
• CM Integration
How do we make it sustainable?
• Always start by writing a test for the easiest success
  case
• “Listen” to the tests to get rid of uncertainty in the high
  level design
• Always make the tests send correct messages when
  running
• Minimize the implementation overhead:
   – Only write tests that you would like to read –
     focused, well named, nicely written
   – Updating the code => updating test code
Three laws of TDD
• First Law You may not write production code
  until you have written a failing test.
• Second Law You may not write more of a test
  than is sufficient to fail, and not compiling is
  failing.
• Third Law You may not write more production
  code than is sufficient to pass the currently
  failing test.
Food for thought…
• http://msdn.microsoft.com/en-
  us/library/hh212233.aspx
• Clean Code A Handbook of Agile Software
  Crafts [Robert Martin]
• Working effectively with legacy code [Martin
  Fowler]
• Growing object-oriented software guided by
  tests [Steve Freeman, Nat Pryce]

More Related Content

What's hot

Test driven development vs Behavior driven development
Test driven development vs Behavior driven developmentTest driven development vs Behavior driven development
Test driven development vs Behavior driven developmentGallop Solutions
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDDavid Rodenas
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGOAgile Montréal
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!Kaizenko
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven DevelopmentViraf Karai
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief exampleJeremy Kendall
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Zohirul Alam Tiemoon
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 

What's hot (20)

Test driven development vs Behavior driven development
Test driven development vs Behavior driven developmentTest driven development vs Behavior driven development
Test driven development vs Behavior driven development
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven Development
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief example
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
TDD and Getting Paid
TDD and Getting PaidTDD and Getting Paid
TDD and Getting Paid
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 

Similar to Tdd

An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1Blue Elephant Consulting
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)Peter Kofler
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Adopting Agile
Adopting AgileAdopting Agile
Adopting AgileCoverity
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented TestingDamian T. Gordon
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping QualityMichael Roufa
 
Test driven development
Test driven developmentTest driven development
Test driven developmentSunil Prasad
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated TestingLars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introductionSergei Kukharev
 
2015 msu-code-review
2015 msu-code-review2015 msu-code-review
2015 msu-code-reviewc.titus.brown
 

Similar to Tdd (20)

An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Adopting Agile
Adopting AgileAdopting Agile
Adopting Agile
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping Quality
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introduction
 
Tdd
TddTdd
Tdd
 
2015 msu-code-review
2015 msu-code-review2015 msu-code-review
2015 msu-code-review
 

Tdd

  • 1. Test Driven Development • What’s that? • The good… • The bad… • And the ugly… • How do we begin? • How do we make it sustainable? • Food for thought
  • 2. What’s that? 1. Write a failing test 2. Get it to compile. 3. Make it pass (do not change existing code). 4. Refactor to remove duplication. 5. Repeat.
  • 3.
  • 4. The good… • Edit and pray vs. Cover and Modify • Feedback, feedback, feedback! • Get a living Documentation • You have nothing to lose but your bugs! • Helps you design on the go • Makes ownership transfer much easier • Gives you more confidence in making changes to the code
  • 5. The good… • It’s highly likely that the code you write will: – Do what it’s meant to do! – Keep methods short & simple – Keep dependencies as weak as possible – Go 100% for Single Responsibility – Not have duplicates – Be protected from invalid input – Have many other qualities that make it awesome 
  • 6. The bad… • You have to break some habits • You’ll have some development time overhead • You need to keep the test code as clean as the production code • You still need the high level designs • You still need more testing
  • 7. And the ugly… • TDD is only good when it’s done properly • Coding Ain’t Done ‘Til All the Tests Run*… AND pass!
  • 8. Is it worth it?! • 100k lines of code => 15 issues 6 months after the release • There’s no bug-free product, but there are collateral issues safe nets.
  • 9. How do we begin? 1. Understand the problem 2. High-level architecture 3. Ensure automation for: – Writing tests – Building – Running Tests 4. Write a failing acceptance test = walking skeleton  5. Write a failing unit test 6. Make the unit test pass 7. Refactor 8. Repeat Steps 5-7 until you make the acceptance test pass 9. Repeat Steps 4-8 until all the acceptance tests pass.
  • 10. Automation tools • Tests Explorer (VS2012) • MSUnit – As simple as “Create New Project” – Generate methods from Unit Tests (VS2012) • Microsoft Fakes • Code Coverage Tools • CM Integration
  • 11. How do we make it sustainable? • Always start by writing a test for the easiest success case • “Listen” to the tests to get rid of uncertainty in the high level design • Always make the tests send correct messages when running • Minimize the implementation overhead: – Only write tests that you would like to read – focused, well named, nicely written – Updating the code => updating test code
  • 12. Three laws of TDD • First Law You may not write production code until you have written a failing test. • Second Law You may not write more of a test than is sufficient to fail, and not compiling is failing. • Third Law You may not write more production code than is sufficient to pass the currently failing test.
  • 13. Food for thought… • http://msdn.microsoft.com/en- us/library/hh212233.aspx • Clean Code A Handbook of Agile Software Crafts [Robert Martin] • Working effectively with legacy code [Martin Fowler] • Growing object-oriented software guided by tests [Steve Freeman, Nat Pryce]