SlideShare une entreprise Scribd logo
1  sur  40
Overcoming the Obstacles,
Pitfalls, and Dangers of
Automated Testing

      Stephen D. Ritchie
      13-Nov-2012
Live Tweet, Tonight’s Slides and Examples




• Twitter:      @RuthlessHelp
                @Apress

• Slideshare: http://www.slideshare.net/ruthlesshelp

• Github:       http://github.com/ruthlesshelp




                             Excella Consulting
Purpose




               Useful

          Automated Testing

   Make Software Better
                Excella Consulting
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   -4-
Chrysler New Yorker




                      Excella Consulting
First Topic: Motivation




                    Why Write
                    Unit Tests?
             Why Automate
               Testing?
                          Excella Consulting
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   -7-
Visibility & Insight

Problem Detection

Advance Warning
Microscope: Visibility and Insight




                               Excella Consulting
Smoke Detector: Problem Detection




                           Excella Consulting
Weather Satellite: Advance Warning




                            Excella Consulting
Example




           Perhaps
          An Example
           Would Be
            Helpful

             Excella Consulting
Automated Tests
  Make Sure
Software Works
  As Intended
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   - 14 -
Principles




        Zero Configuration
                  Fast
               Clear Result
             Easy To Maintain
                   Excella Consulting
Automated Testing: Vocabulary




• Test-Driven Development (TDD)
    – Write a Test, Watch the Test Fail
    – Write Code, Make the Test Pass
    – Write the Next Test


• Behavior-Driven Development (BDD)
    – Given a Desired Behavior


• Intention Checking
    – The Software Works, As Intended




                                 Excella Consulting
Principles




        Zero Configuration

 I can run your tests,
 You can run mine.

              Excella Consulting
Principles




             Fast

    All the tests run in
    just a few minutes

             Excella Consulting
Principles




             Clear Results

              Pass/Fail
             Focused Test

                 Excella Consulting
Principles




             Easy to Maintain

             Conventional
                  Brief

                  Excella Consulting
The Long-Term Goals




• Automated Testing
    – Vigilantly Monitoring the Code
• Readability
    – Have Mercy on Future Developers
        • Conventional
        • Short, Clear
• Maintainability
    – Both a Sword and a Shield
        • Code Works as Intended
        • Protects Against Regression
    – Reliable
    – N+1 is Easy




                                 Excella Consulting
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   - 22 -
One Primary Assert To Rule Them All




                   Obstacle 1
        Over-Specifying



                            Excella Consulting
One Primary Assert To Rule Them All




• Is your effort to refactor and improve code overwhelmed by the
  time it takes to maintain/update/rewrite all those failing unit tests?
    – Your test-code could be over specifying things.


• Perhaps an example would be helpful …




                               Excella Consulting
One Primary Assert To Rule Them All




• Debate: Only one assertion per test?

• Test Method Tests One and Only One Scenario
    – 1 Primary Assert Verifies and Validates the Scenario


• Secondary Asserts
    – Support Arrangement and Preconditions
    – Support Post-Conditions


• Avoid Asserts that Over Specify
    – Too Literal => Inhibited Refactoring
    – Imagined Benefit => Rigidity



                               Excella Consulting
Four Ways to Fake Time




                  Obstacle 2
             Time Crunch



                         Excella Consulting
Four Ways to Fake Time




• Are your test methods starting to fail because the code-under-test is
  coupled to the system clock?
    – Your code is too dependent on   System.DateTime.Now

• Perhaps an example would be helpful …




                              Excella Consulting
Four Ways to Fake Time




• Things to Watch For
    – Thread Safety
       • public static class SystemDateTime

   – Making Your Privates Public
   // Inject the class dependency on DateTime.Now
   private DateTime? _now;
   public DateTime Now
   {
       get { return _now ?? DateTime.Now; }
       set { _now = value; }
   }



                          Excella Consulting
Database Killed The Integration Test




                   Obstacle 3
                   Database



                             Excella Consulting
Database Killed The Integration Test




• Are your automated integration tests failing because of the data in
  the testing database; the data keeps changing?

• Perhaps an example would be helpful …




                             Excella Consulting
Database Killed The Integration Test




• Automated Testing Persistence
    – NDbUnit
    – SQL Server Express
    – NHibernate


• Surface Testing
    – Data Access Layer: API Surface
    – Liberates Refactoring




                              Excella Consulting
In Test Code, Do Repeat Yourself ... Do Repeat Yourself




         Obstacle 4
     Unhelpful …
        Reuse
        Repetition
        Coupling
                             Excella Consulting
In Test Code, Do Repeat Yourself ... Do Repeat Yourself




• Do you have an explosion of test methods, with the ratio of test
  code to code-under-test that’s way too high?
    – Your test-code is too DRY in some places and …
    – Not DRY enough in all the right places


• Perhaps an example would be helpful …




                              Excella Consulting
In Test Code, Do Repeat Yourself ... Do Repeat Yourself




• Data-Drive Test Cases
    – One Test Method
    – Many Test Scenarios
• Repeat Code in a “TestsContext” Class
    – Sidecar Approach
• Use Helper Classes
    – Extension methods
    – Composition
• Keep Inheritance in Reserve
    – Overall Testing Framework




                             Excella Consulting
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   - 35 -
Of Course It’s Safe … After You




                             Excella Consulting
Further Discussion




            Any questions?

           Any comments?


                     Excella Consulting
Shameless Self Promotion Time!




                            40% off eBook at
                            apress.com

                            Use promo code:
                            PR0N3T

                            Offer ends 15-Dec-2012




                            Excella Consulting
Contact Me




• Twitter:    @ruthlesshelp

• Email:      stephen.ritchie@excella.com

• Blog:       http://ruthlesslyhelpful.net

• LinkedIn:   http://www.linkedin.com/in/sritchie




                           Excella Consulting
Slides and Examples




• Slideshare: http://www.slideshare.net/ruthlesshelp

• Github:      http://github.com/ruthlesshelp




                           Excella Consulting

Contenu connexe

Tendances

Erkki Poyhonen - Software Testing - A Users Guide
Erkki Poyhonen - Software Testing - A Users GuideErkki Poyhonen - Software Testing - A Users Guide
Erkki Poyhonen - Software Testing - A Users GuideTEST Huddle
 
Will The Test Leaders Stand Up?
Will The Test Leaders Stand Up?Will The Test Leaders Stand Up?
Will The Test Leaders Stand Up?Paul Gerrard
 
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010TEST Huddle
 
Rethinking the Role of Testers
Rethinking the Role of TestersRethinking the Role of Testers
Rethinking the Role of TestersPaul Gerrard
 
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010TEST Huddle
 
Test Cases are dead, long live Checklists!
Test Cases are dead, long live Checklists!Test Cases are dead, long live Checklists!
Test Cases are dead, long live Checklists!SQALab
 
10 signs your testing is not enough
10 signs your testing is not enough10 signs your testing is not enough
10 signs your testing is not enoughSQALab
 
TDD Refresh - Austin RB - 2013-07-01 - public
TDD Refresh - Austin RB - 2013-07-01 - publicTDD Refresh - Austin RB - 2013-07-01 - public
TDD Refresh - Austin RB - 2013-07-01 - publicsbellware
 
Gustav Olsson - Agile - Common Sense with a New Name Tag revised
Gustav Olsson - Agile - Common Sense with a New Name Tag revisedGustav Olsson - Agile - Common Sense with a New Name Tag revised
Gustav Olsson - Agile - Common Sense with a New Name Tag revisedTEST Huddle
 
Test Automation Patterns: Issues and Solutions
Test Automation Patterns: Issues and SolutionsTest Automation Patterns: Issues and Solutions
Test Automation Patterns: Issues and SolutionsTechWell
 
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)Yuriy Tymchuk
 
The Test Coverage Outline: Your Testing Road Map
The Test Coverage Outline: Your Testing Road MapThe Test Coverage Outline: Your Testing Road Map
The Test Coverage Outline: Your Testing Road MapTechWell
 
Test analysis & design good practices@TDT Iasi 17Oct2013
Test analysis & design   good practices@TDT Iasi 17Oct2013Test analysis & design   good practices@TDT Iasi 17Oct2013
Test analysis & design good practices@TDT Iasi 17Oct2013Tabăra de Testare
 
Starting data science with kaggle.com
Starting data science with kaggle.comStarting data science with kaggle.com
Starting data science with kaggle.comNathaniel Shimoni
 
Next-Generation Performance Testing with Lifecycle Monitoring
Next-Generation Performance Testing with Lifecycle MonitoringNext-Generation Performance Testing with Lifecycle Monitoring
Next-Generation Performance Testing with Lifecycle MonitoringTechWell
 
Common Technical Writing Issues
Common Technical Writing IssuesCommon Technical Writing Issues
Common Technical Writing IssuesTao Xie
 
Offline evaluation of recommender systems: all pain and no gain?
Offline evaluation of recommender systems: all pain and no gain?Offline evaluation of recommender systems: all pain and no gain?
Offline evaluation of recommender systems: all pain and no gain?Mark Levy
 
Test Strategy-The real silver bullet in testing by Matthew Eakin
Test Strategy-The real silver bullet in testing by Matthew EakinTest Strategy-The real silver bullet in testing by Matthew Eakin
Test Strategy-The real silver bullet in testing by Matthew EakinQA or the Highway
 
STARCANADA 2013 Keynote: Lightning Strikes the Keynotes
STARCANADA 2013 Keynote: Lightning Strikes the KeynotesSTARCANADA 2013 Keynote: Lightning Strikes the Keynotes
STARCANADA 2013 Keynote: Lightning Strikes the KeynotesTechWell
 

Tendances (20)

Erkki Poyhonen - Software Testing - A Users Guide
Erkki Poyhonen - Software Testing - A Users GuideErkki Poyhonen - Software Testing - A Users Guide
Erkki Poyhonen - Software Testing - A Users Guide
 
Will The Test Leaders Stand Up?
Will The Test Leaders Stand Up?Will The Test Leaders Stand Up?
Will The Test Leaders Stand Up?
 
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010
Stefaan Luckermans - Number for Passion, Passion for Numbers - EuroSTAR 2010
 
Rethinking the Role of Testers
Rethinking the Role of TestersRethinking the Role of Testers
Rethinking the Role of Testers
 
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010
Tafline Murnane - The Carrot or The Whip-What Motivates Testers? - EuroSTAR 2010
 
Test Cases are dead, long live Checklists!
Test Cases are dead, long live Checklists!Test Cases are dead, long live Checklists!
Test Cases are dead, long live Checklists!
 
10 signs your testing is not enough
10 signs your testing is not enough10 signs your testing is not enough
10 signs your testing is not enough
 
TDD Refresh - Austin RB - 2013-07-01 - public
TDD Refresh - Austin RB - 2013-07-01 - publicTDD Refresh - Austin RB - 2013-07-01 - public
TDD Refresh - Austin RB - 2013-07-01 - public
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
Gustav Olsson - Agile - Common Sense with a New Name Tag revised
Gustav Olsson - Agile - Common Sense with a New Name Tag revisedGustav Olsson - Agile - Common Sense with a New Name Tag revised
Gustav Olsson - Agile - Common Sense with a New Name Tag revised
 
Test Automation Patterns: Issues and Solutions
Test Automation Patterns: Issues and SolutionsTest Automation Patterns: Issues and Solutions
Test Automation Patterns: Issues and Solutions
 
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)
JIT Feedback — what Experienced Developers like about Static Analysis (icpc2018)
 
The Test Coverage Outline: Your Testing Road Map
The Test Coverage Outline: Your Testing Road MapThe Test Coverage Outline: Your Testing Road Map
The Test Coverage Outline: Your Testing Road Map
 
Test analysis & design good practices@TDT Iasi 17Oct2013
Test analysis & design   good practices@TDT Iasi 17Oct2013Test analysis & design   good practices@TDT Iasi 17Oct2013
Test analysis & design good practices@TDT Iasi 17Oct2013
 
Starting data science with kaggle.com
Starting data science with kaggle.comStarting data science with kaggle.com
Starting data science with kaggle.com
 
Next-Generation Performance Testing with Lifecycle Monitoring
Next-Generation Performance Testing with Lifecycle MonitoringNext-Generation Performance Testing with Lifecycle Monitoring
Next-Generation Performance Testing with Lifecycle Monitoring
 
Common Technical Writing Issues
Common Technical Writing IssuesCommon Technical Writing Issues
Common Technical Writing Issues
 
Offline evaluation of recommender systems: all pain and no gain?
Offline evaluation of recommender systems: all pain and no gain?Offline evaluation of recommender systems: all pain and no gain?
Offline evaluation of recommender systems: all pain and no gain?
 
Test Strategy-The real silver bullet in testing by Matthew Eakin
Test Strategy-The real silver bullet in testing by Matthew EakinTest Strategy-The real silver bullet in testing by Matthew Eakin
Test Strategy-The real silver bullet in testing by Matthew Eakin
 
STARCANADA 2013 Keynote: Lightning Strikes the Keynotes
STARCANADA 2013 Keynote: Lightning Strikes the KeynotesSTARCANADA 2013 Keynote: Lightning Strikes the Keynotes
STARCANADA 2013 Keynote: Lightning Strikes the Keynotes
 

Similaire à Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing

Automated Testing: Obstacles, Pitfalls, and Dangers
Automated Testing: Obstacles, Pitfalls, and DangersAutomated Testing: Obstacles, Pitfalls, and Dangers
Automated Testing: Obstacles, Pitfalls, and DangersStephen Ritchie
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best PracticesStephen Ritchie
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with DatabasesStephen Ritchie
 
Advancing Testing Using Axioms
Advancing Testing Using AxiomsAdvancing Testing Using Axioms
Advancing Testing Using AxiomsSQALab
 
Dare to Explore: Discover ET!
Dare to Explore: Discover ET!Dare to Explore: Discover ET!
Dare to Explore: Discover ET!Raj Indugula
 
ACC presentation for QA Club Kiev
ACC presentation for QA Club KievACC presentation for QA Club Kiev
ACC presentation for QA Club KievNikita Knysh
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
A New Model for Testing
A New Model for TestingA New Model for Testing
A New Model for TestingSQALab
 
STOP! You're Testing Too Much - Shawn Wallace
STOP!  You're Testing Too Much - Shawn WallaceSTOP!  You're Testing Too Much - Shawn Wallace
STOP! You're Testing Too Much - Shawn WallaceQA or the Highway
 
Stop! you're testing too much
Stop!  you're testing too muchStop!  you're testing too much
Stop! you're testing too muchShawn Wallace
 
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
 
A New Model For Testing
A New Model For TestingA New Model For Testing
A New Model For TestingTEST Huddle
 
New Model Testing: A New Test Process and Tool
New Model Testing:  A New Test Process and ToolNew Model Testing:  A New Test Process and Tool
New Model Testing: A New Test Process and ToolTEST Huddle
 
Session-Based Test Management
Session-Based Test ManagementSession-Based Test Management
Session-Based Test Managementcaltonhill
 
Search Solutions 2015: Towards a new model of search relevance testing
Search Solutions 2015:  Towards a new model of search relevance testingSearch Solutions 2015:  Towards a new model of search relevance testing
Search Solutions 2015: Towards a new model of search relevance testingCharlie Hull
 
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don Peters
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don PetersMHA2018 - Quality Advocacy: The next progression for Agile Testers - Don Peters
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don PetersAgileDenver
 
My Experiments In Agile Testing in Yahoo.pptx
My Experiments In Agile Testing in Yahoo.pptxMy Experiments In Agile Testing in Yahoo.pptx
My Experiments In Agile Testing in Yahoo.pptxBaiju Joseph
 

Similaire à Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing (20)

Automated Testing: Obstacles, Pitfalls, and Dangers
Automated Testing: Obstacles, Pitfalls, and DangersAutomated Testing: Obstacles, Pitfalls, and Dangers
Automated Testing: Obstacles, Pitfalls, and Dangers
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best Practices
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databases
 
Advancing Testing Using Axioms
Advancing Testing Using AxiomsAdvancing Testing Using Axioms
Advancing Testing Using Axioms
 
Dare to Explore: Discover ET!
Dare to Explore: Discover ET!Dare to Explore: Discover ET!
Dare to Explore: Discover ET!
 
Delhi it professionals
Delhi it professionalsDelhi it professionals
Delhi it professionals
 
ACC presentation for QA Club Kiev
ACC presentation for QA Club KievACC presentation for QA Club Kiev
ACC presentation for QA Club Kiev
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
A New Model for Testing
A New Model for TestingA New Model for Testing
A New Model for Testing
 
STOP! You're Testing Too Much - Shawn Wallace
STOP!  You're Testing Too Much - Shawn WallaceSTOP!  You're Testing Too Much - Shawn Wallace
STOP! You're Testing Too Much - Shawn Wallace
 
Stop! you're testing too much
Stop!  you're testing too muchStop!  you're testing too much
Stop! you're testing too much
 
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
 
New model
New modelNew model
New model
 
A New Model For Testing
A New Model For TestingA New Model For Testing
A New Model For Testing
 
New Model Testing: A New Test Process and Tool
New Model Testing:  A New Test Process and ToolNew Model Testing:  A New Test Process and Tool
New Model Testing: A New Test Process and Tool
 
Session-Based Test Management
Session-Based Test ManagementSession-Based Test Management
Session-Based Test Management
 
Search Solutions 2015: Towards a new model of search relevance testing
Search Solutions 2015:  Towards a new model of search relevance testingSearch Solutions 2015:  Towards a new model of search relevance testing
Search Solutions 2015: Towards a new model of search relevance testing
 
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don Peters
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don PetersMHA2018 - Quality Advocacy: The next progression for Agile Testers - Don Peters
MHA2018 - Quality Advocacy: The next progression for Agile Testers - Don Peters
 
My Experiments In Agile Testing in Yahoo.pptx
My Experiments In Agile Testing in Yahoo.pptxMy Experiments In Agile Testing in Yahoo.pptx
My Experiments In Agile Testing in Yahoo.pptx
 
Ml2 production
Ml2 productionMl2 production
Ml2 production
 

Plus de Stephen Ritchie

Overview of .NET Best Practices
Overview of .NET Best PracticesOverview of .NET Best Practices
Overview of .NET Best PracticesStephen Ritchie
 
Lightweight Documentation
Lightweight DocumentationLightweight Documentation
Lightweight DocumentationStephen Ritchie
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Stephen Ritchie
 
Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Stephen Ritchie
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachStephen Ritchie
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftStephen Ritchie
 
Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Stephen Ritchie
 
Test Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftTest Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftStephen Ritchie
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftStephen Ritchie
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12Stephen Ritchie
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best PracticesStephen Ritchie
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NETStephen Ritchie
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best PracticesStephen Ritchie
 
Advanced Code Analysis In .NET
Advanced Code Analysis In .NETAdvanced Code Analysis In .NET
Advanced Code Analysis In .NETStephen Ritchie
 

Plus de Stephen Ritchie (15)

Overview of .NET Best Practices
Overview of .NET Best PracticesOverview of .NET Best Practices
Overview of .NET Best Practices
 
Lightweight Documentation
Lightweight DocumentationLightweight Documentation
Lightweight Documentation
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015
 
DevOps Requires Agility
DevOps Requires AgilityDevOps Requires Agility
DevOps Requires Agility
 
Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile Approach
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
 
Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923
 
Test Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftTest Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master Craft
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NET
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
Advanced Code Analysis In .NET
Advanced Code Analysis In .NETAdvanced Code Analysis In .NET
Advanced Code Analysis In .NET
 

Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing

  • 1. Overcoming the Obstacles, Pitfalls, and Dangers of Automated Testing Stephen D. Ritchie 13-Nov-2012
  • 2. Live Tweet, Tonight’s Slides and Examples • Twitter: @RuthlessHelp @Apress • Slideshare: http://www.slideshare.net/ruthlesshelp • Github: http://github.com/ruthlesshelp Excella Consulting
  • 3. Purpose Useful Automated Testing Make Software Better Excella Consulting
  • 4. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting -4-
  • 5. Chrysler New Yorker Excella Consulting
  • 6. First Topic: Motivation Why Write Unit Tests? Why Automate Testing? Excella Consulting
  • 7. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting -7-
  • 8. Visibility & Insight Problem Detection Advance Warning
  • 9. Microscope: Visibility and Insight Excella Consulting
  • 10. Smoke Detector: Problem Detection Excella Consulting
  • 11. Weather Satellite: Advance Warning Excella Consulting
  • 12. Example Perhaps An Example Would Be Helpful Excella Consulting
  • 13. Automated Tests Make Sure Software Works As Intended
  • 14. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 14 -
  • 15. Principles Zero Configuration Fast Clear Result Easy To Maintain Excella Consulting
  • 16. Automated Testing: Vocabulary • Test-Driven Development (TDD) – Write a Test, Watch the Test Fail – Write Code, Make the Test Pass – Write the Next Test • Behavior-Driven Development (BDD) – Given a Desired Behavior • Intention Checking – The Software Works, As Intended Excella Consulting
  • 17. Principles Zero Configuration I can run your tests, You can run mine. Excella Consulting
  • 18. Principles Fast All the tests run in just a few minutes Excella Consulting
  • 19. Principles Clear Results Pass/Fail Focused Test Excella Consulting
  • 20. Principles Easy to Maintain Conventional Brief Excella Consulting
  • 21. The Long-Term Goals • Automated Testing – Vigilantly Monitoring the Code • Readability – Have Mercy on Future Developers • Conventional • Short, Clear • Maintainability – Both a Sword and a Shield • Code Works as Intended • Protects Against Regression – Reliable – N+1 is Easy Excella Consulting
  • 22. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 22 -
  • 23. One Primary Assert To Rule Them All Obstacle 1 Over-Specifying Excella Consulting
  • 24. One Primary Assert To Rule Them All • Is your effort to refactor and improve code overwhelmed by the time it takes to maintain/update/rewrite all those failing unit tests? – Your test-code could be over specifying things. • Perhaps an example would be helpful … Excella Consulting
  • 25. One Primary Assert To Rule Them All • Debate: Only one assertion per test? • Test Method Tests One and Only One Scenario – 1 Primary Assert Verifies and Validates the Scenario • Secondary Asserts – Support Arrangement and Preconditions – Support Post-Conditions • Avoid Asserts that Over Specify – Too Literal => Inhibited Refactoring – Imagined Benefit => Rigidity Excella Consulting
  • 26. Four Ways to Fake Time Obstacle 2 Time Crunch Excella Consulting
  • 27. Four Ways to Fake Time • Are your test methods starting to fail because the code-under-test is coupled to the system clock? – Your code is too dependent on System.DateTime.Now • Perhaps an example would be helpful … Excella Consulting
  • 28. Four Ways to Fake Time • Things to Watch For – Thread Safety • public static class SystemDateTime – Making Your Privates Public // Inject the class dependency on DateTime.Now private DateTime? _now; public DateTime Now { get { return _now ?? DateTime.Now; } set { _now = value; } } Excella Consulting
  • 29. Database Killed The Integration Test Obstacle 3 Database Excella Consulting
  • 30. Database Killed The Integration Test • Are your automated integration tests failing because of the data in the testing database; the data keeps changing? • Perhaps an example would be helpful … Excella Consulting
  • 31. Database Killed The Integration Test • Automated Testing Persistence – NDbUnit – SQL Server Express – NHibernate • Surface Testing – Data Access Layer: API Surface – Liberates Refactoring Excella Consulting
  • 32. In Test Code, Do Repeat Yourself ... Do Repeat Yourself Obstacle 4 Unhelpful … Reuse Repetition Coupling Excella Consulting
  • 33. In Test Code, Do Repeat Yourself ... Do Repeat Yourself • Do you have an explosion of test methods, with the ratio of test code to code-under-test that’s way too high? – Your test-code is too DRY in some places and … – Not DRY enough in all the right places • Perhaps an example would be helpful … Excella Consulting
  • 34. In Test Code, Do Repeat Yourself ... Do Repeat Yourself • Data-Drive Test Cases – One Test Method – Many Test Scenarios • Repeat Code in a “TestsContext” Class – Sidecar Approach • Use Helper Classes – Extension methods – Composition • Keep Inheritance in Reserve – Overall Testing Framework Excella Consulting
  • 35. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 35 -
  • 36. Of Course It’s Safe … After You Excella Consulting
  • 37. Further Discussion Any questions? Any comments? Excella Consulting
  • 38. Shameless Self Promotion Time! 40% off eBook at apress.com Use promo code: PR0N3T Offer ends 15-Dec-2012 Excella Consulting
  • 39. Contact Me • Twitter: @ruthlesshelp • Email: stephen.ritchie@excella.com • Blog: http://ruthlesslyhelpful.net • LinkedIn: http://www.linkedin.com/in/sritchie Excella Consulting
  • 40. Slides and Examples • Slideshare: http://www.slideshare.net/ruthlesshelp • Github: http://github.com/ruthlesshelp Excella Consulting