SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Improving Design through
Test Driven Development (TDD)
     Sam Brown @SamuelBrownIV
     Mike McGarr @jmichaelmcgarr

    DC Agile Engineering Conference
               #DCAEC12
About Us
            Sam Brown                      Mike McGarr
•   11 years software engineer     • 11 years software engineer
•   DevOps Evangelist at Excella   • Directory of DevOps for
•   Certified Scrum Master           Blackboard Learn
•   Puppet Certified               • Founder of the DC
    Professional                     Continuous Integration,
                                     Delivery and Deployment
                                     Meetup
Types of Tests
Unit Tests

Fast
Independent
Repeatable
Self-Verifying
Timely
Test Driven Development
                                                                     Golden Rule of
                                                                     TDD:
                                                                     Never write
                                                                     production code
                                                                     without a failing
                                                                     test




 http://reddevnews.com/articles/2007/11/01/testdriven-development-tdd.aspx
TDD improves quality and
                                   design




http://www.manning.com/koskela2/
Coupling
Cohesion
Object Oriented Design Principles
  Single responsibility principle (SRP)

  Open/close principle (OCP)

  Liskov substitution principle (LSP)

  Interface segregation principle (ISP)

  Dependency inversion principle (DSP)
Bowling Game
• Ten Frames per game
• 2 rolls per frame
   • Unless a strike is rolled
• Properly calculate Spares
• Properly calculate Strikes
                                 http://playcasper.com/venues/show/17
Design
Decision
Design
Decision
Notice the duplication
  in the tests. Let’s
     refactor this.
More duplication
Design
                  Problem – roll()
                  calculates score




Let’s Refactor!
We need a concept of
      frames.
Ugly Code
Design Decisions
• Design client interface

• Refactor
     • Change design without changing behavior


• Defer to last responsible moment
     • Avoids “Big Upfront Design”
New Requirements!
Requested Changes
The Bowling game is becoming service oriented!

• New Requirement:
  – Post rolls in real-time
Collaborator
Test Doubles

•   Dummy
•   Stubs
•   Fake
•   Mocks
•   Spy
NullPointerException!
 We need a default
  implementation.
Contact Us
Sam Brown
samuel.brown@excella.com                 Cute Baby Arrival
@SamuelBrownIV                             12/20/2012
https://github.com/samueltbrown



                             •    J. Michael McGarr
                             •    jmcgarr@gmail.com
                             •    @jmichaelmcgarr
                             •    http://earlyandoften.wordpress.com
                             •    DC CI Meetup - http://bit.ly/YRnrwx

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (19)

Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Tomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance TuningTomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance Tuning
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
SD DevOps Meet-up - Exploring Quadrants of DevOps Maturity
SD DevOps Meet-up - Exploring Quadrants of DevOps MaturitySD DevOps Meet-up - Exploring Quadrants of DevOps Maturity
SD DevOps Meet-up - Exploring Quadrants of DevOps Maturity
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Learning to Sense and Respond - the Fujitsu Service Case
Learning to Sense and Respond - the Fujitsu Service CaseLearning to Sense and Respond - the Fujitsu Service Case
Learning to Sense and Respond - the Fujitsu Service Case
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talks
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
DOES15 - Sherry Chang - Intel’s Journey to Large Scale DevOps Transformation
DOES15 - Sherry Chang - Intel’s Journey to Large Scale DevOps Transformation DOES15 - Sherry Chang - Intel’s Journey to Large Scale DevOps Transformation
DOES15 - Sherry Chang - Intel’s Journey to Large Scale DevOps Transformation
 
NetflixOSS Meetup
NetflixOSS MeetupNetflixOSS Meetup
NetflixOSS Meetup
 
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-CodeSD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
 
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...
 
Splitting the Check on Compliance and Security
Splitting the Check on Compliance and SecuritySplitting the Check on Compliance and Security
Splitting the Check on Compliance and Security
 
(DVO203) The Life of a Netflix Engineer Using 37% of the Internet
(DVO203) The Life of a Netflix Engineer Using 37% of the Internet(DVO203) The Life of a Netflix Engineer Using 37% of the Internet
(DVO203) The Life of a Netflix Engineer Using 37% of the Internet
 
NLP pipeline in machine translation
NLP pipeline in machine translationNLP pipeline in machine translation
NLP pipeline in machine translation
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Devops at Netflix (re:Invent)
Devops at Netflix (re:Invent)Devops at Netflix (re:Invent)
Devops at Netflix (re:Invent)
 
Past, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry PerspectivePast, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry Perspective
 

Mehr von Excella

Using Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of AgileUsing Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of Agile
Excella
 

Mehr von Excella (20)

DCSUG - What's Really Going On? Observer Worksheet
DCSUG - What's Really Going On? Observer WorksheetDCSUG - What's Really Going On? Observer Worksheet
DCSUG - What's Really Going On? Observer Worksheet
 
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa AdkinsDCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
 
DCSUG - Servant Leadership Handout
DCSUG - Servant Leadership HandoutDCSUG - Servant Leadership Handout
DCSUG - Servant Leadership Handout
 
DCSUG - Servant Leadership
DCSUG - Servant LeadershipDCSUG - Servant Leadership
DCSUG - Servant Leadership
 
DCSUG - Applying Analysis in an Agile World
DCSUG - Applying Analysis in an Agile WorldDCSUG - Applying Analysis in an Agile World
DCSUG - Applying Analysis in an Agile World
 
DCSUG - The Art and Practice of the Agile Leader
DCSUG - The Art and Practice of the Agile LeaderDCSUG - The Art and Practice of the Agile Leader
DCSUG - The Art and Practice of the Agile Leader
 
DCSUG - Finding Lean in Agile
DCSUG - Finding Lean in AgileDCSUG - Finding Lean in Agile
DCSUG - Finding Lean in Agile
 
DCSUG - Impact Mapping
DCSUG - Impact MappingDCSUG - Impact Mapping
DCSUG - Impact Mapping
 
DCSUG - Happiness: A Key Component of Agile
DCSUG - Happiness: A Key Component of AgileDCSUG - Happiness: A Key Component of Agile
DCSUG - Happiness: A Key Component of Agile
 
The Awkward Teenager of Testing
The Awkward Teenager of TestingThe Awkward Teenager of Testing
The Awkward Teenager of Testing
 
Let's Sharpen Your Agile Ax, It's Story Splitting Time
Let's Sharpen Your Agile Ax, It's Story Splitting TimeLet's Sharpen Your Agile Ax, It's Story Splitting Time
Let's Sharpen Your Agile Ax, It's Story Splitting Time
 
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
 
The 7 Secrets of Highly Effective Retrospectives (DCSUG)
The 7 Secrets of Highly Effective Retrospectives (DCSUG)The 7 Secrets of Highly Effective Retrospectives (DCSUG)
The 7 Secrets of Highly Effective Retrospectives (DCSUG)
 
Get Your Productivity Game On!!
Get Your Productivity Game On!!Get Your Productivity Game On!!
Get Your Productivity Game On!!
 
How to Structure Multi Team Organizations
How to Structure Multi Team OrganizationsHow to Structure Multi Team Organizations
How to Structure Multi Team Organizations
 
Tactics to Kickstart Your Journey Toward DevOps
Tactics to Kickstart Your Journey Toward DevOpsTactics to Kickstart Your Journey Toward DevOps
Tactics to Kickstart Your Journey Toward DevOps
 
Intro to Mocking - DjangoCon 2015
Intro to Mocking - DjangoCon 2015Intro to Mocking - DjangoCon 2015
Intro to Mocking - DjangoCon 2015
 
Tactics to Kickstart Your Journey Toward Continuous Delivery
Tactics to Kickstart Your Journey Toward Continuous DeliveryTactics to Kickstart Your Journey Toward Continuous Delivery
Tactics to Kickstart Your Journey Toward Continuous Delivery
 
Using ansible vault to protect your secrets
Using ansible vault to protect your secretsUsing ansible vault to protect your secrets
Using ansible vault to protect your secrets
 
Using Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of AgileUsing Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of Agile
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Improving Design Through Test Driven Development (TDD)

Hinweis der Redaktion

  1. Mike
  2. (Mike)Fast – runs in less than 1/10 secondIndependent– test one thing only (single assert)Repeatable – reliably repeatable (no external dependencies)Self-Verifying – red or green…no human interpretationTimely – test written before production code
  3. (Sam)Red-Green-RefactorRefactoring – changing code without changing behaviorGolden Rule of TDD: Never write production code without a failing test
  4. (Sam)Unit testing alone helps focus on qualityQuality only unit testing has limitsTDD allows developers to also improve design, increasing the value of testsLasseKoskela calls this the law of two plateausTransition to Advantage:Commonly understood advantage: QualityLess known: Improving DesignAdditional Voice Track: As we approach 100% coverage, effort to achieve small increases in coverage are greater than the value returned
  5. (Mike)Metrics of maintainability:Coupled Elements – A change in one forces a change in another (want loose coupling)Inheritance vs. Interface
  6. (Sam)Coherence – a measure of whether an element’s responsibility form a meaningful unit.Do one thing only-Animation to show first class, then divided out- What the heck is ‘coherence’???
  7. SRP – do one thing only (coherence)OCP – objects should be open for extension/closed for modificationLSP – objects should be replaceable by sub-types (design by contract)ISP – many client specific interfaces are better than one multi-purpose oneDSP – depend on abstractions and not concrete classes (dependency inversion)
  8. Calculate score for bowlsUnderstand sparesUnderstand strikes
  9. Test to ensure JUnit is working
  10. First design decision
  11. Only going to talk about Stubs and MocksDummy – objects that are passed but never usedStubs – pre-canned answers to method callsFake – scaled down version of production (InMemoryDB)Mocks – set expectationsSpy – records information passed to it
  12. Introduce a new test
  13. 1. ImportMockito (discuss what it is)2. Declare interface and use Mockito to mock3. Define dependency injection of RollNotificationService4. Then,…roll5. Verify that the mock RollNotificationService’s publish method was called once
  14. We create the new interfaceTest still failsIf we look at the unit test, the Game object needs to be updated
  15. We now update the Game with dependencySOLID – Dependency InversionTest still failsOur interface needs a new publish method
  16. We add method to interfaceTest still failsWe’ve resolved all compilation errorsThe roll() method never calls publish!The error we get is different…not an assertion
  17. Add the call to the serviceTest fails! (Huh?!)All other tests fail due to NullPointerException(Emphasize how powerful this fast feedback is on regressions)
  18. Created a new default implementation(would likely not do this in production…let me know if we should change to another type or demand)