SlideShare une entreprise Scribd logo
1  sur  20
Test Driven Development
    Working with Legacy Code




          Guy Davis
        Pason Systems
Introduction

    TDD is a changed mindset for development




    One of the cornerstones of the Agile movement




    Rejection of the defined engineering approach




        No detailed designs set in stone up front
    −

        Embraces change through refactoring
    −

    Result is more cohesive and less coupled code




    Regression test bed and easier integration

TDD Process
                      Complex view
                        1. Add a little test
                        2. Run all tests and fail
Simple view
                        3. Make a little change
   1. Make a test       4. Run all the tests and
                          succeed
   2. Make it run
                        5. Refactor to remove
                          duplication
   3. Make it right
Introductory Exercise
               Given three integers
           

               representing the length
               of the sides of a triangle
               return:

                    1 if equilateral
                



                    2 if isosceles
                



                    3 if scalene
                



               Throw an exception if
           

               not well formed.
Writing tests
    Chose a simple test first, use small steps...




    When you have a list of tests, order them to get most


    benefit up front.

    Forces you to define interfaces early on




    One thing at a time; keep a to-do list




    What to test:




         Requirements, assumptions, boundary cases
     −

         Goal is to get 100% code coverage with tests
     −
Making tests run

    TDD book offers three main approaches:




        Fake It
    −

        Triangulation
    −

        Obvious Implementation
    −

    Goal is to get a passing test ASAP




        The longer a test is failing, the less confident you
    −
        are
Fake It

    Purpose is to get test running ASAP




    Ignore coding conventions




    Example: addition operation




    Why?




        Let's us take little steps...
    −

        Provides more refactoring confidence
    −

        Keeps work focused
    −
Triangulation

    How can we abstract conservatively with tests?




    Example: addition operation




    Safest way to abstract an operation




    Allows for very small steps:




        Why are small steps important?
    −

        Do you always want to take small steps?
    −
Obvious Implementation

    When small steps are too slow




    Simply implement the solution you see




    Faster, but...




         Important to watch that bar isn't red for long or
     −
         often

         Harder: solving both “code that works” and “clean
     −
         code” at the same time

         Shouldn't keep getting test failures doing this
     −
Make it right
    Remove code duplication (including tests)




    Meet coding standards




    Refactor code




        Reconcile differences
    −

        Isolate change
    −

        Move method
    −

        Extract method / Inline method
    −

        Extract interface
    −
Patterns
                        Red Bar Patterns
                            One step test
                        
TDD Patterns
                            Starter test
                        
    Isolated test



                            Explanation test
                        
    Test list


                            Learning test
                        

    Test first


                            Regression test
                        

    Assert first




    Evident data

Patterns
                         Green Bar Patterns
Testing Patterns
                             Fake it
                         

    Child test

                             Triangulate
                         


                             Obvious
    Mock object

                         

                             Implementation
    Log string



                             One to many
                         

    Crash test dummy




    Broken test




    Clean check-in

TDD of Legacy code

1. Identify change points
2. Find an inflection point
3. Cover the inflection point
   a) Break the dependencies

   b) Write tests

4. Make changes
5. Refactor the covered code
Change Points

    Where will changes need to be made in code?




    Don't assume the first spot you find is the best




        Approach resulting in fewest changes may be
    −
        good?

        What about approach using simplest design?
    −

        Better to work in area with existing unit tests
    −

    Debuggers are useful in this stage

Inflection Point

    A narrow interface to a set of classes or functions




    Any changes in classes behind an inflection point are


    either detectable at the inflection point or
    inconsequential to the application.

    Inflection points determined by compile time and


    run time dependencies and code behavior.

    What are some examples from the your project?

Covering an Inflection Point


    Covering with unit tests (islands of test)




    Legacy code: no tests means lots of dependencies




         If class, try to create an instance to see links
     −

         If method, look at signature (and for globals)
     −

         Look at interactions with data and resources
     −
Breaking Dependencies
    Database:




        Find the smallest slice of data needed to get
    −
        functionality to run; everything else null/empty.

    Class:




        Mock object: just answers back constants
    −

        Self shunt: object communicates with test case
    −

    Method:




        Build up structures manually, don't rely on
    −
        complex helper methods
Writing Covering Tests
    Goal is to determine the current behavior




    Reverse of TDD; covering existing functions




    Some tips




         Test at the boundary values
     −

         Ensure “golden” or normal values are tested
     −

         Tests for handled error conditions
     −

    Correctness is just the behavior of system now




    If lucky, can use old requirements docs :)

Make changes

    Now that area has test coverage, make changes




    Use the full TDD cycle for the changes




    Run the tests often




    Refactor as much as needed




        Extract method (create test first)
    −

        Extract class refactoring
    −

        Many others...
    −
References

    Beck, Kent. Test-Driven Development: By Example. Addison-Wesley. 2003





    Feathers. Michael. Working Effectively with Legacy Code. Object Mentor,


    Inc. 2002. http://www.objectmentor.com/resources/articles/
    WorkingEffectivelyWithLegacyCode.pdf

    Parrish, Alan et al. Ordering Test Cases to Maximize Early Testing.


    University of Alabama. 2003. http://www.agilealliance.com/articles/articles/
    ExtremeUnitTesting.pdf

    Ynchausti, Randy A. Integrating Unit Testing Into a Software


    Development Team's Process. Monster Consulting. 2003. http://
    www.agilealliance.com/articles/articles/IntegratingUnitTesting.pdf

Contenu connexe

Tendances

TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
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
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentJohn Blum
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)Brian Rasmussen
 
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 DevelopmentMireia Sangalo
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-developmentDavid Paluy
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOSPablo Villar
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect coupleStephen Tucker
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentConsulthinkspa
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 

Tendances (20)

TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
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)
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 
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
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-development
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect couple
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Atdd half day_new_1_up
Atdd half day_new_1_upAtdd half day_new_1_up
Atdd half day_new_1_up
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 

Similaire à Test Driven Development

Selected Sessions from RailsConf 2007
Selected Sessions from RailsConf 2007Selected Sessions from RailsConf 2007
Selected Sessions from RailsConf 2007Jerry Richardson
 
Unit testing
Unit testingUnit testing
Unit testingAdam Birr
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development Amir Assad
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development IntroductionNguyen Hai
 
Unit Testing
Unit TestingUnit Testing
Unit TestingAdam Birr
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit TestingWen-Tien Chang
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...Steve Lange
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Javaguy_davis
 
Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert daysOren Rubin
 
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationJust Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationDaniel Wildt
 
The Art of Unit Testing Feedback
The Art of Unit Testing FeedbackThe Art of Unit Testing Feedback
The Art of Unit Testing FeedbackDeon Huang
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...FalafelSoftware
 
Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017David Völkel
 

Similaire à Test Driven Development (20)

Selected Sessions from RailsConf 2007
Selected Sessions from RailsConf 2007Selected Sessions from RailsConf 2007
Selected Sessions from RailsConf 2007
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
TDD and Getting Paid
TDD and Getting PaidTDD and Getting Paid
TDD and Getting Paid
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Test Driven
Test DrivenTest Driven
Test Driven
 
Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert days
 
Testing smells
Testing smellsTesting smells
Testing smells
 
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationJust Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
 
The Art of Unit Testing Feedback
The Art of Unit Testing FeedbackThe Art of Unit Testing Feedback
The Art of Unit Testing Feedback
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
 
Tdd guide
Tdd guideTdd guide
Tdd guide
 
Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017
 

Plus de guy_davis

Adopting Scrum and Agile
Adopting Scrum and AgileAdopting Scrum and Agile
Adopting Scrum and Agileguy_davis
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic Programmerguy_davis
 
Content Caching with Rails
Content Caching with RailsContent Caching with Rails
Content Caching with Railsguy_davis
 
Agile Software Development Methodologies
Agile Software Development MethodologiesAgile Software Development Methodologies
Agile Software Development Methodologiesguy_davis
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Controlguy_davis
 
The Human Side of Software Development
The Human Side of Software DevelopmentThe Human Side of Software Development
The Human Side of Software Developmentguy_davis
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Patternguy_davis
 
Software Quality Plan
Software Quality PlanSoftware Quality Plan
Software Quality Planguy_davis
 
Unified Process
Unified ProcessUnified Process
Unified Processguy_davis
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Managementguy_davis
 
Quality Function Deployment
Quality Function DeploymentQuality Function Deployment
Quality Function Deploymentguy_davis
 

Plus de guy_davis (11)

Adopting Scrum and Agile
Adopting Scrum and AgileAdopting Scrum and Agile
Adopting Scrum and Agile
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic Programmer
 
Content Caching with Rails
Content Caching with RailsContent Caching with Rails
Content Caching with Rails
 
Agile Software Development Methodologies
Agile Software Development MethodologiesAgile Software Development Methodologies
Agile Software Development Methodologies
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Control
 
The Human Side of Software Development
The Human Side of Software DevelopmentThe Human Side of Software Development
The Human Side of Software Development
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Software Quality Plan
Software Quality PlanSoftware Quality Plan
Software Quality Plan
 
Unified Process
Unified ProcessUnified Process
Unified Process
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Management
 
Quality Function Deployment
Quality Function DeploymentQuality Function Deployment
Quality Function Deployment
 

Dernier

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Dernier (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Test Driven Development

  • 1. Test Driven Development Working with Legacy Code Guy Davis Pason Systems
  • 2. Introduction TDD is a changed mindset for development  One of the cornerstones of the Agile movement  Rejection of the defined engineering approach  No detailed designs set in stone up front − Embraces change through refactoring − Result is more cohesive and less coupled code  Regression test bed and easier integration 
  • 3. TDD Process Complex view 1. Add a little test 2. Run all tests and fail Simple view 3. Make a little change 1. Make a test 4. Run all the tests and succeed 2. Make it run 5. Refactor to remove duplication 3. Make it right
  • 4. Introductory Exercise Given three integers  representing the length of the sides of a triangle return: 1 if equilateral  2 if isosceles  3 if scalene  Throw an exception if  not well formed.
  • 5. Writing tests Chose a simple test first, use small steps...  When you have a list of tests, order them to get most  benefit up front. Forces you to define interfaces early on  One thing at a time; keep a to-do list  What to test:  Requirements, assumptions, boundary cases − Goal is to get 100% code coverage with tests −
  • 6. Making tests run TDD book offers three main approaches:  Fake It − Triangulation − Obvious Implementation − Goal is to get a passing test ASAP  The longer a test is failing, the less confident you − are
  • 7. Fake It Purpose is to get test running ASAP  Ignore coding conventions  Example: addition operation  Why?  Let's us take little steps... − Provides more refactoring confidence − Keeps work focused −
  • 8. Triangulation How can we abstract conservatively with tests?  Example: addition operation  Safest way to abstract an operation  Allows for very small steps:  Why are small steps important? − Do you always want to take small steps? −
  • 9. Obvious Implementation When small steps are too slow  Simply implement the solution you see  Faster, but...  Important to watch that bar isn't red for long or − often Harder: solving both “code that works” and “clean − code” at the same time Shouldn't keep getting test failures doing this −
  • 10. Make it right Remove code duplication (including tests)  Meet coding standards  Refactor code  Reconcile differences − Isolate change − Move method − Extract method / Inline method − Extract interface −
  • 11. Patterns Red Bar Patterns One step test  TDD Patterns Starter test  Isolated test  Explanation test  Test list  Learning test  Test first  Regression test  Assert first  Evident data 
  • 12. Patterns Green Bar Patterns Testing Patterns Fake it  Child test  Triangulate  Obvious Mock object   Implementation Log string  One to many  Crash test dummy  Broken test  Clean check-in 
  • 13. TDD of Legacy code 1. Identify change points 2. Find an inflection point 3. Cover the inflection point a) Break the dependencies b) Write tests 4. Make changes 5. Refactor the covered code
  • 14. Change Points Where will changes need to be made in code?  Don't assume the first spot you find is the best  Approach resulting in fewest changes may be − good? What about approach using simplest design? − Better to work in area with existing unit tests − Debuggers are useful in this stage 
  • 15. Inflection Point A narrow interface to a set of classes or functions  Any changes in classes behind an inflection point are  either detectable at the inflection point or inconsequential to the application. Inflection points determined by compile time and  run time dependencies and code behavior. What are some examples from the your project? 
  • 16. Covering an Inflection Point Covering with unit tests (islands of test)  Legacy code: no tests means lots of dependencies  If class, try to create an instance to see links − If method, look at signature (and for globals) − Look at interactions with data and resources −
  • 17. Breaking Dependencies Database:  Find the smallest slice of data needed to get − functionality to run; everything else null/empty. Class:  Mock object: just answers back constants − Self shunt: object communicates with test case − Method:  Build up structures manually, don't rely on − complex helper methods
  • 18. Writing Covering Tests Goal is to determine the current behavior  Reverse of TDD; covering existing functions  Some tips  Test at the boundary values − Ensure “golden” or normal values are tested − Tests for handled error conditions − Correctness is just the behavior of system now  If lucky, can use old requirements docs :) 
  • 19. Make changes Now that area has test coverage, make changes  Use the full TDD cycle for the changes  Run the tests often  Refactor as much as needed  Extract method (create test first) − Extract class refactoring − Many others... −
  • 20. References Beck, Kent. Test-Driven Development: By Example. Addison-Wesley. 2003  Feathers. Michael. Working Effectively with Legacy Code. Object Mentor,  Inc. 2002. http://www.objectmentor.com/resources/articles/ WorkingEffectivelyWithLegacyCode.pdf Parrish, Alan et al. Ordering Test Cases to Maximize Early Testing.  University of Alabama. 2003. http://www.agilealliance.com/articles/articles/ ExtremeUnitTesting.pdf Ynchausti, Randy A. Integrating Unit Testing Into a Software  Development Team's Process. Monster Consulting. 2003. http:// www.agilealliance.com/articles/articles/IntegratingUnitTesting.pdf

Notes de l'éditeur

  1. This was an in-house seminar I gave for our development team (6 people) at work to help us get over the initial challenges in writing unit tests for our code. The presentation and discussion only took an hour or so. Then we split up into pairs and worked on adding unit tests to our untested Java, C, and Python code for an afternoon. We then held an hour long meeting to discuss the outcome of the pair work. Details about test frameworks, what worked, what didn't, etc. were discussed.
  2. Reverses the order of typical development. (Where tests are often skipped or ignored at the end) Quote: “If you can't write a test for what you are about to code, then you shouldn't even be thinking about coding.” Dramatically narrows the gap between intent and result in software development. Unintended errors are found much sooner, which saves time and cost.
  3. 1) Write a test: - Think about the task in your mind. - Invent interfaces you wish you had. - Include all the elements needed. 2) Make it run: - Quickly get the bar green with new test - If can see a solution requiring a while to write, just write it down on To-Do list - Will cover in details approaches for this... - Ignore coding standard, use constants, etc... 3) Make it right (refactor): - Now remove code duplication - Meet coding standards - Keep the bar green!
  4. Ask that they cover the method/class with unit tests. Stress the importance of recording the order in which they work. What steps did they follow? Give them about 5-10 minutes. Answer questions as they work. Then discuss for 5 minutes: What tests did they choose and why? Show my example with 6 tests, other author did 65 How many is enough?
  5. Greedy ordering algorithm: “Write some tests and write the methods that allow you to run more tests sooner.” Describe task lists: OPT task list for main work tasks Pad of paper for things to not forget Evolution task list for TDD coding Keeps my ideas for other tests, possible refactorings, etc. Anything that distracts from current test I'm in. Coverage in industry can be 80-90%
  6. “Code that works” stage
  7. Give example of addition operation on board: Test: assert(7 == Integer.add(five, two)) Code: return (5+2); hard-coded Metaphor of rock climber getting to far above last attachment point Psychological benefit to seeing bar green is more confidence Concentrating on a single test means you'll do a better job of it, than juggling two or three at a time.
  8. Start with one test: assert(7 == Integer.add(five, two)) Code: return 7; Add more asserts to a test case assert(4 == Integer.add(two, two)) Now must correct implementation to pass new asserts private int add(int augend, int addend) { return augend + addend };
  9. Emphasize the power of choice here to go fast or slow during development. How many times have we seen the same problem occur again in a edit, compile, debug cycle? Unit tests prevent this type of regression. If making the same mistake, then
  10. “Clean code” stage...
  11. See Beck's TDD book for details.
  12. See Beck's TDD book for details.
  13. First ask what they consider legacy code? Can be defined as any code without automated unit tests.
  14. Methods: - debugger to step through - code tracing - runtime logging
  15. Method example: parsing a data line of EDR data need array of params and column mapping. Rather than hit the database, I just populate the array with the ones I need manually. Other ways of breaking external dependencies? Refactoring... example Extract Method...
  16. Notice, I say “handled” error conditions. These coverage tests only test the current functionality. If an error condition isn't handled, put it on your to-do for later. No refactoring of code yet! Why is it important to separate out the coverage test writing from refactoring and not mix them?
  17. If can't find a decent inflection point, may need to use system boundaries. This requires writing smoke tests against the whole system as described by McConnell.