SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Destaque

Scatol8 UUDD_livello A_5
Scatol8 UUDD_livello A_5Scatol8 UUDD_livello A_5
Scatol8 UUDD_livello A_5
Scatol8
 
Overloading in java with example
Overloading in java with exampleOverloading in java with example
Overloading in java with example
kalkanpal
 
Bcg case competition team 2 final for linked_in
Bcg case competition team 2 final for linked_inBcg case competition team 2 final for linked_in
Bcg case competition team 2 final for linked_in
Naian Chang
 
26598353 laporan-kerja-milling-2
26598353 laporan-kerja-milling-226598353 laporan-kerja-milling-2
26598353 laporan-kerja-milling-2
Muiz Rosli
 
Sistem tagal
Sistem tagalSistem tagal
Sistem tagal
sutang
 
Scatol8 UUDD livello A_1
Scatol8 UUDD livello A_1Scatol8 UUDD livello A_1
Scatol8 UUDD livello A_1
Scatol8
 
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
Scatol8
 
IoT and Management Systems: new dimensions for research and didactics towards...
IoT and Management Systems: new dimensions for research and didactics towards...IoT and Management Systems: new dimensions for research and didactics towards...
IoT and Management Systems: new dimensions for research and didactics towards...
Scatol8
 
Coffee Shop Security Group Tool
Coffee Shop Security Group ToolCoffee Shop Security Group Tool
Coffee Shop Security Group Tool
joehack3r
 

Destaque (20)

lecture(1)
lecture(1)lecture(1)
lecture(1)
 
Kcw rb
Kcw rbKcw rb
Kcw rb
 
Scatol8 UUDD_livello A_5
Scatol8 UUDD_livello A_5Scatol8 UUDD_livello A_5
Scatol8 UUDD_livello A_5
 
Overloading in java with example
Overloading in java with exampleOverloading in java with example
Overloading in java with example
 
وسل أبها
وسل أبهاوسل أبها
وسل أبها
 
2015 寒假實習簡報 - 網站建置流程
2015 寒假實習簡報 - 網站建置流程2015 寒假實習簡報 - 網站建置流程
2015 寒假實習簡報 - 網站建置流程
 
Bcg case competition team 2 final for linked_in
Bcg case competition team 2 final for linked_inBcg case competition team 2 final for linked_in
Bcg case competition team 2 final for linked_in
 
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
 
26598353 laporan-kerja-milling-2
26598353 laporan-kerja-milling-226598353 laporan-kerja-milling-2
26598353 laporan-kerja-milling-2
 
Trabajo grupal
Trabajo grupalTrabajo grupal
Trabajo grupal
 
Awareness on public school education
Awareness on public school educationAwareness on public school education
Awareness on public school education
 
Sistem tagal
Sistem tagalSistem tagal
Sistem tagal
 
Spaeth claritypp002W
Spaeth claritypp002WSpaeth claritypp002W
Spaeth claritypp002W
 
Tmđt
TmđtTmđt
Tmđt
 
Scatol8 UUDD livello A_1
Scatol8 UUDD livello A_1Scatol8 UUDD livello A_1
Scatol8 UUDD livello A_1
 
Saludos navideños docentes
Saludos navideños docentesSaludos navideños docentes
Saludos navideños docentes
 
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
ECO-ARREDI: ARREDO COMFORT BENESSERE SU MISURA DA MATRICI NATURALI SOSTENIBIL...
 
Feliz dia del maestro.pptx rr
Feliz dia del maestro.pptx rrFeliz dia del maestro.pptx rr
Feliz dia del maestro.pptx rr
 
IoT and Management Systems: new dimensions for research and didactics towards...
IoT and Management Systems: new dimensions for research and didactics towards...IoT and Management Systems: new dimensions for research and didactics towards...
IoT and Management Systems: new dimensions for research and didactics towards...
 
Coffee Shop Security Group Tool
Coffee Shop Security Group ToolCoffee Shop Security Group Tool
Coffee Shop Security Group Tool
 

Semelhante a Improving Design through TDD

SanDiego_DevOps_Meetup_9212016-v8
SanDiego_DevOps_Meetup_9212016-v8SanDiego_DevOps_Meetup_9212016-v8
SanDiego_DevOps_Meetup_9212016-v8
Rajwinder Singh
 
SanDiego_DevOps_Meetup_9212016
SanDiego_DevOps_Meetup_9212016SanDiego_DevOps_Meetup_9212016
SanDiego_DevOps_Meetup_9212016
w2fong
 
Managing Software Debt - Quality Debt Focus - QASIG Kirkland
Managing Software Debt - Quality Debt Focus - QASIG KirklandManaging Software Debt - Quality Debt Focus - QASIG Kirkland
Managing Software Debt - Quality Debt Focus - QASIG Kirkland
Chris Sterling
 

Semelhante a Improving Design through TDD (20)

JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
SanDiego_DevOps_Meetup_9212016-v8
SanDiego_DevOps_Meetup_9212016-v8SanDiego_DevOps_Meetup_9212016-v8
SanDiego_DevOps_Meetup_9212016-v8
 
SanDiego_DevOps_Meetup_9212016
SanDiego_DevOps_Meetup_9212016SanDiego_DevOps_Meetup_9212016
SanDiego_DevOps_Meetup_9212016
 
Managing Software Debt - Quality Debt Focus - QASIG Kirkland
Managing Software Debt - Quality Debt Focus - QASIG KirklandManaging Software Debt - Quality Debt Focus - QASIG Kirkland
Managing Software Debt - Quality Debt Focus - QASIG Kirkland
 
Scaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel DevelopmentScaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel Development
 
Production - Designing for Testability
Production - Designing for TestabilityProduction - Designing for Testability
Production - Designing for Testability
 
Inside Behavior Driven Development
Inside Behavior Driven DevelopmentInside Behavior Driven Development
Inside Behavior Driven Development
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
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)
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About Testing
 
Behavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineBehavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & Jasmine
 
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
 
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build TimesUsing Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
 
Continuous Integration, the minimum viable product
Continuous Integration, the minimum viable productContinuous Integration, the minimum viable product
Continuous Integration, the minimum viable product
 
Ruin your life using robot framework
Ruin your life using robot frameworkRuin your life using robot framework
Ruin your life using robot framework
 
Metrics-driven Continuous Delivery
Metrics-driven Continuous DeliveryMetrics-driven Continuous Delivery
Metrics-driven Continuous Delivery
 
Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
 
CodeOne 2018 - Better software, faster: principles of Continuous Delivery and...
CodeOne 2018 - Better software, faster: principles of Continuous Delivery and...CodeOne 2018 - Better software, faster: principles of Continuous Delivery and...
CodeOne 2018 - Better software, faster: principles of Continuous Delivery and...
 
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)
 

Mais de DC Agile Engineering Conference (6)

Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
 
Unindented Code Cannot Possibly Work
Unindented Code Cannot Possibly WorkUnindented Code Cannot Possibly Work
Unindented Code Cannot Possibly Work
 
Lead by Example
Lead by ExampleLead by Example
Lead by Example
 
Continuous Integration: Toolbox, Blueprint, Master Craft
Continuous Integration: Toolbox, Blueprint, Master CraftContinuous Integration: Toolbox, Blueprint, Master Craft
Continuous Integration: Toolbox, Blueprint, Master Craft
 
Continuous Delivery Applied
Continuous Delivery AppliedContinuous Delivery Applied
Continuous Delivery Applied
 
Agile Engineering and Software Craftsmanship
Agile Engineering and Software CraftsmanshipAgile Engineering and Software Craftsmanship
Agile Engineering and Software Craftsmanship
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.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
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech 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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Improving Design through TDD

Notas do Editor

  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)