SlideShare a Scribd company logo
http://dc-agile-engineering-conference.eventbrite.com/
Overcoming the Obstacles,
Pitfalls, and Dangers of
Automated Testing

      Stephen D. Ritchie
      16-Oct-2012
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:
                            UGoCTNoV

                            Offer ends 10-Nov-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

More Related Content

PPTX
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
PPTX
Level Up Your Automated Tests
PDF
Level Up Your Automated Tests
PPTX
Testing a movingtarget_quest_dynatrace
PPTX
Intro to TDD
PPT
Software Testing with Agile Requirements Practices
PDF
Offline evaluation of recommender systems: all pain and no gain?
PPTX
Prototyping
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Level Up Your Automated Tests
Level Up Your Automated Tests
Testing a movingtarget_quest_dynatrace
Intro to TDD
Software Testing with Agile Requirements Practices
Offline evaluation of recommender systems: all pain and no gain?
Prototyping

What's hot (11)

PDF
Test Automation Patterns: Issues and Solutions
PDF
RecSys 2016 Talk: Feature Selection For Human Recommenders
PDF
Common Technical Writing Issues
PPTX
Starting data science with kaggle.com
PDF
Lean DevOps - Lessons Learned from Innovation-driven Companies
PPT
STARCANADA 2013 Keynote: Lightning Strikes the Keynotes
PPTX
Testing katas - Try before you buy
PDF
Replication of Recommender Systems Research
PPTX
Test Design For Everyone
PDF
How to prepare for ieee se certifications
PPTX
How Technology Can Help Students Improving their Performance in competitive e...
Test Automation Patterns: Issues and Solutions
RecSys 2016 Talk: Feature Selection For Human Recommenders
Common Technical Writing Issues
Starting data science with kaggle.com
Lean DevOps - Lessons Learned from Innovation-driven Companies
STARCANADA 2013 Keynote: Lightning Strikes the Keynotes
Testing katas - Try before you buy
Replication of Recommender Systems Research
Test Design For Everyone
How to prepare for ieee se certifications
How Technology Can Help Students Improving their Performance in competitive e...
Ad

Similar to DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers (20)

PPTX
Automated Testing: Obstacles, Pitfalls, and Dangers
PPTX
Agile Testing Best Practices
PPTX
Automated Testing with Databases
PPT
feature-selection.ppt on machine learning
PPTX
Advancing Testing Using Axioms
PPTX
An Overview of .NET Best Practices
PPTX
An Overview of .NET Best Practices
PPT
Delhi it professionals
PDF
Dare to Explore: Discover ET!
PPTX
A Brief Introduction to Test-Driven Development
PPTX
A New Model for Testing
PDF
Unit Testing Best Practices
PPT
Arch factory - Agile Design: Best Practices
PPTX
ACC presentation for QA Club Kiev
ODP
Search Solutions 2015: Towards a new model of search relevance testing
PPTX
New model
PPTX
A New Model For Testing
PPTX
Code review
PPTX
Ml2 production
PPTX
New Model Testing: A New Test Process and Tool
Automated Testing: Obstacles, Pitfalls, and Dangers
Agile Testing Best Practices
Automated Testing with Databases
feature-selection.ppt on machine learning
Advancing Testing Using Axioms
An Overview of .NET Best Practices
An Overview of .NET Best Practices
Delhi it professionals
Dare to Explore: Discover ET!
A Brief Introduction to Test-Driven Development
A New Model for Testing
Unit Testing Best Practices
Arch factory - Agile Design: Best Practices
ACC presentation for QA Club Kiev
Search Solutions 2015: Towards a new model of search relevance testing
New model
A New Model For Testing
Code review
Ml2 production
New Model Testing: A New Test Process and Tool
Ad

More from Stephen Ritchie (13)

PPTX
Overview of .NET Best Practices
PPTX
Lightweight Documentation
PPTX
Agile Engineering Sparker GLASScon 2015
PPTX
DevOps Requires Agility
PPTX
Continuous Integration - NoVA CodeCamp 2014-10-11
PPTX
Lightweight Documentation: An Agile Approach
PPTX
Continuous Integration: Blueprint, Toolbox, Master Craft
PDF
Dc scrum agile_eng_20130923
PPTX
Test Driven Development: Blueprint, Toolbox, and Master Craft
PPTX
Continuous Integration: Blueprint, Toolbox, Master Craft
PPTX
Continuous Integration DCAEC12
PPTX
Advanced Code Analysis with .NET
PPTX
Advanced Code Analysis In .NET
Overview of .NET Best Practices
Lightweight Documentation
Agile Engineering Sparker GLASScon 2015
DevOps Requires Agility
Continuous Integration - NoVA CodeCamp 2014-10-11
Lightweight Documentation: An Agile Approach
Continuous Integration: Blueprint, Toolbox, Master Craft
Dc scrum agile_eng_20130923
Test Driven Development: Blueprint, Toolbox, and Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration DCAEC12
Advanced Code Analysis with .NET
Advanced Code Analysis In .NET

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
sap open course for s4hana steps from ECC to s4
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
sap open course for s4hana steps from ECC to s4
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf

DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers

  • 2. Overcoming the Obstacles, Pitfalls, and Dangers of Automated Testing Stephen D. Ritchie 16-Oct-2012
  • 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: UGoCTNoV Offer ends 10-Nov-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