SlideShare a Scribd company logo
Test Driven Development	Why I hate it, but really love it.
Start with FAIL
Make it Green!
Make it Pretty (refactor)(Not Like this chap)
Eh?Why???How???When???
						WHY TDD?
Stability
Flexibility
Documentation
MORE SPEEEEDzzz
Design
HOW TDD?(Disclaimer: Code incoming!)
Writing an adding, er.. Thing…Failing Test:def test_add_1_plus_1assert_equal 2, add(1,1)endOutput:tdd.rb:6:in `test_add_1_plus_1': undefined method `add' for main:Object (NoMethodError)from tdd.rb:9
WHATS THE NEXT STEP?
Make it pass:def add(i,j)   return 2endOutput:Loaded suite TddExampleStarted.Finished in 0.000455 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
Waait!! Why isn’t it just:def add(i,j)   return i+jend
WHATS THE NEXT STEP?
Write another failing test:def test_add_1_plus_2assert_equal 3, add(1,2)EndLoaded suite TddExampleStartedFFinished in 0.042739 seconds.1) Failure:test_add_1_plus_1(TddExample) [tdd.rb:42]:<3> expected but was<2>.1 tests, 1 assertions, 1 failures, 0 errors
Make it pass:def add(i,j)  return i+jEndLoaded suite TddExampleStarted..Finished in 0.000462 seconds.2 tests, 2 assertions, 0 failures, 0 errors
All about the baby steps
Problems?
add(1,2,3)Fail.add(1,”two”)Fail.
How do we cope?
Any number of arguments?First add a test..def test_adding_three_argumentsassert_equal 4, add(1,2,1)EndMake it pass!!Add another test!!def test_adding_four_argumentsassert_equal 8, add(1,2,1,4)end
RefactorFor the general solution:def add(*args)  return args.inject(0){|sum,n| sum + n}EndLoaded suite TddExampleStarted....Finished in 0.000941 seconds.4 tests, 4 assertions, 0 failures, 0 errors
Dependency Injection(This has nothing to do with children)
Example:class PersonDAO  def initialize(user, password)    @data_source = Database.connect(user, password)  endendVSclass PersonDAO  def initialize(data_source)    @data_source = data_source  endend
Why is this better?
And you’re telling me this… why?
Start off with a testdef setup  @person = FamilGuyDao.newenddef test_return_full_name_is_reginald_von_griffenassert_equal "Reginald Von-Griffin", @person.full_nameend#But how do we make it vary? Pass in the name? Pull it from somewhere #Lets assume there is some Griffin Family Tree in the skydef test_return_full_name_is_stewie_griffinassert_equal "Stewie Griffin", @person.full_name end
For now we’ll pass in the name
Next Test….
Make it pass…
WHATS THE NEXT STEP?
The General CaseIntegration faked by Mock object!
MAKE IT PASS!!
DONE!

More Related Content

PPT
Advanced PHPUnit Testing
PPT
Test Driven Development with PHPUnit
PPTX
Testers guide to unit testing
PDF
PHPUnit best practices presentation
PDF
Test your code like a pro - PHPUnit in practice
PPTX
PHPUnit: from zero to hero
PDF
Introduction to Unit Testing with PHPUnit
Advanced PHPUnit Testing
Test Driven Development with PHPUnit
Testers guide to unit testing
PHPUnit best practices presentation
Test your code like a pro - PHPUnit in practice
PHPUnit: from zero to hero
Introduction to Unit Testing with PHPUnit

What's hot (20)

PDF
Testing in Django
PDF
PhpUnit Best Practices
ODP
Automated Testing in Django
PDF
Python unittest
PDF
New Features PHPUnit 3.3 - Sebastian Bergmann
 
PPT
Working Effectively with Legacy Code (draft)
PPT
Unit Testing using PHPUnit
PDF
Unit testing with PHPUnit - there's life outside of TDD
PPT
Google mock for dummies
PDF
Test Driven Development With Python
PPTX
Unit Testng with PHP Unit - A Step by Step Training
PDF
Basic TDD moves
PDF
Unit Testing in Angular(7/8/9) Using Jasmine and Karma Part-2
PPTX
Unit Testing Presentation
PPTX
unittest in 5 minutes
PDF
Python Unit Test
PPT
Phpunit testing
PPT
Python testing
PDF
C++ Unit Test with Google Testing Framework
PDF
Dart Unit Testing
Testing in Django
PhpUnit Best Practices
Automated Testing in Django
Python unittest
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Working Effectively with Legacy Code (draft)
Unit Testing using PHPUnit
Unit testing with PHPUnit - there's life outside of TDD
Google mock for dummies
Test Driven Development With Python
Unit Testng with PHP Unit - A Step by Step Training
Basic TDD moves
Unit Testing in Angular(7/8/9) Using Jasmine and Karma Part-2
Unit Testing Presentation
unittest in 5 minutes
Python Unit Test
Phpunit testing
Python testing
C++ Unit Test with Google Testing Framework
Dart Unit Testing
Ad

Similar to Test Driven Development: Why I hate it; but secretly love it. (20)

PPT
Behaviour-Driven Development
KEY
Tdd for BT E2E test community
PDF
Beyond Testing: Specs and Behavior Driven Development
PDF
iOS Test-Driven Development
PDF
TDD step patterns
PPT
Test Driven Development
PPTX
Test-Driven Development
PDF
Test Driven Development - Workshop
ODP
Effective TDD - Less is more
PDF
Test Driven Development
PPTX
Intro to TDD and BDD
PPTX
TDD & Refactoring
PDF
Test Driven Development Introduction
PPTX
Tdd is not about testing (OOP)
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
ZIP
Test Driven Development
PPTX
Tdd and-bdd
PPTX
Tdd guide
PPTX
TDD - Seriously, try it - Codemotion (May '24)
PPTX
TDD - Seriously, try it! - Bucarest Tech Week
Behaviour-Driven Development
Tdd for BT E2E test community
Beyond Testing: Specs and Behavior Driven Development
iOS Test-Driven Development
TDD step patterns
Test Driven Development
Test-Driven Development
Test Driven Development - Workshop
Effective TDD - Less is more
Test Driven Development
Intro to TDD and BDD
TDD & Refactoring
Test Driven Development Introduction
Tdd is not about testing (OOP)
TDD and Simple Design Workshop - Session 1 - March 2019
Test Driven Development
Tdd and-bdd
Tdd guide
TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it! - Bucarest Tech Week
Ad

More from Tom Crinson (8)

PPT
Destructuring demystified
KEY
Hidden treasures of Ruby
ODP
Crystal Agile
PPTX
Javascript Basics for Advertisers
ODP
A few questions on MongoDB
ODP
Higher Order Ruby
ODP
Itty bittypresentation lrug
ODP
Object Oriented Design Principles - SOLID
Destructuring demystified
Hidden treasures of Ruby
Crystal Agile
Javascript Basics for Advertisers
A few questions on MongoDB
Higher Order Ruby
Itty bittypresentation lrug
Object Oriented Design Principles - SOLID

Recently uploaded (20)

PDF
Lesson 9 _ the role of plantrdetrtbtvrcterxwctvyrbutynibvrtcewrxctv and anim...
PDF
2, 3, and 4 BHK Superior Apartment in Coimbatore
PDF
Chelsea Residences 1 at Dubai Maritime City – DAMAC Properties
PPTX
Tangled Up in Green Luxury Developments
PDF
Collaborating-for-a-Better-Future-Cross-Sector-Partnerships-in-Miami.pdf
PDF
Expert Advice on Property Development Finance for 2025.pdf
PDF
BAYZ 102 at Business Bay, Dubai – Danube Properties
PDF
Signature Global Twin Tower - Sector-84, Gurgaon
PPTX
Classifying Objects and Events or Situations.pptx
PDF
Binghatti Haven at Dubai Sports City -
PDF
Isaş Tem Catalog - Gaziosmanpasa - Listing Turkey
PDF
Real Estate Investment in Trichy – Why 2025 is the Best Time to Invest.pdf
PDF
Luxera Bahceport Project - Listing Turkey
PDF
Evolving Illinois Rental Market: Trends and Opportunities for Landlords
PDF
Blue Breeze Dapoli – A Scenic Coastal Haven
PDF
Binghatti Aquarise at Business Bay, Dubai – Binghatti Developers.pdf
PDF
MSN Realty 4 BHK Luxury Apartments in Neopolis Hyderabad | Premium Homes with...
PPTX
Property Development Finance in Uk, London
PPTX
Startup Business Plan Neon Green and White Modern Minimal Presentation.pptx
PDF
Interstellar Tower at JVT, Dubai – Mr Eight Development
Lesson 9 _ the role of plantrdetrtbtvrcterxwctvyrbutynibvrtcewrxctv and anim...
2, 3, and 4 BHK Superior Apartment in Coimbatore
Chelsea Residences 1 at Dubai Maritime City – DAMAC Properties
Tangled Up in Green Luxury Developments
Collaborating-for-a-Better-Future-Cross-Sector-Partnerships-in-Miami.pdf
Expert Advice on Property Development Finance for 2025.pdf
BAYZ 102 at Business Bay, Dubai – Danube Properties
Signature Global Twin Tower - Sector-84, Gurgaon
Classifying Objects and Events or Situations.pptx
Binghatti Haven at Dubai Sports City -
Isaş Tem Catalog - Gaziosmanpasa - Listing Turkey
Real Estate Investment in Trichy – Why 2025 is the Best Time to Invest.pdf
Luxera Bahceport Project - Listing Turkey
Evolving Illinois Rental Market: Trends and Opportunities for Landlords
Blue Breeze Dapoli – A Scenic Coastal Haven
Binghatti Aquarise at Business Bay, Dubai – Binghatti Developers.pdf
MSN Realty 4 BHK Luxury Apartments in Neopolis Hyderabad | Premium Homes with...
Property Development Finance in Uk, London
Startup Business Plan Neon Green and White Modern Minimal Presentation.pptx
Interstellar Tower at JVT, Dubai – Mr Eight Development

Test Driven Development: Why I hate it; but secretly love it.