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

      Stephen D. Ritchie
      6-Sept-2012
Purpose




               Useful

          Automated Testing

   Make Software Better
                Excella Consulting
Agenda
  1   Motivation

  2   Principles

  3   Obstacles
         Excella Consulting   -3-
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   -6-
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   - 13 -
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   - 21 -
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   - 34 -
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:
                            LIN340

                            Offer ends 6-Oct-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

Tendances (10)

How to Use Innoslate for Beginners
How to Use Innoslate for BeginnersHow to Use Innoslate for Beginners
How to Use Innoslate for Beginners
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Clean tests
Clean testsClean tests
Clean tests
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Single Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance MeetupSingle Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance Meetup
 
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your DocumentationLF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
 
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a... [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 

Similaire à Automated Testing: Obstacles, Pitfalls, and Dangers

DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangersDCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
Stephen Ritchie
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
Tomaš Maconko
 
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
 
Code review
Code reviewCode review
Code review
Aleksey Solntsev
 
ACC presentation for QA Club Kiev
ACC presentation for QA Club KievACC presentation for QA Club Kiev
ACC presentation for QA Club Kiev
Nikita Knysh
 

Similaire à Automated Testing: Obstacles, Pitfalls, and Dangers (20)

DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangersDCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
 
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit TestingOvercoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best Practices
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
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!
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
Delhi it professionals
Delhi it professionalsDelhi it professionals
Delhi it professionals
 
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
 
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
 
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
 
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
 
Code review
Code reviewCode review
Code review
 
ACC presentation for QA Club Kiev
ACC presentation for QA Club KievACC presentation for QA Club Kiev
ACC presentation for QA Club Kiev
 
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
 
Ml2 production
Ml2 productionMl2 production
Ml2 production
 
Code Review
Code ReviewCode Review
Code Review
 

Plus de Stephen 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-11
Stephen Ritchie
 

Plus de Stephen Ritchie (13)

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
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NET
 
Advanced Code Analysis In .NET
Advanced Code Analysis In .NETAdvanced Code Analysis In .NET
Advanced Code Analysis In .NET
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Automated Testing: Obstacles, Pitfalls, and Dangers

  • 1. Overcoming the Obstacles, Pitfalls, and Dangers of Automated Testing Stephen D. Ritchie 6-Sept-2012
  • 2. Purpose Useful Automated Testing Make Software Better Excella Consulting
  • 3. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting -3-
  • 4. Chrysler New Yorker Excella Consulting
  • 5. First Topic: Motivation Why Write Unit Tests? Why Automate Testing? Excella Consulting
  • 6. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting -6-
  • 7. Visibility & Insight Problem Detection Advance Warning
  • 8. Microscope: Visibility and Insight Excella Consulting
  • 9. Smoke Detector: Problem Detection Excella Consulting
  • 10. Weather Satellite: Advance Warning Excella Consulting
  • 11. Example Perhaps An Example Would Be Helpful Excella Consulting
  • 12. Automated Tests Make Sure Software Works As Intended
  • 13. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 13 -
  • 14. Principles Zero Configuration Fast Clear Result Easy To Maintain Excella Consulting
  • 15. 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
  • 16. Principles Zero Configuration I can run your tests, You can run mine. Excella Consulting
  • 17. Principles Fast All the tests run in just a few minutes Excella Consulting
  • 18. Principles Clear Results Pass/Fail Focused Test Excella Consulting
  • 19. Principles Easy to Maintain Conventional Brief Excella Consulting
  • 20. 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
  • 21. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 21 -
  • 22. One Primary Assert To Rule Them All Obstacle 1 Over-Specifying Excella Consulting
  • 23. 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
  • 24. 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
  • 25. Four Ways to Fake Time Obstacle 2 Time Crunch Excella Consulting
  • 26. 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
  • 27. 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
  • 28. Database Killed The Integration Test Obstacle 3 Database Excella Consulting
  • 29. 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
  • 30. Database Killed The Integration Test • Automated Testing Persistence – NDbUnit – SQL Server Express – NHibernate • Surface Testing – Data Access Layer: API Surface – Liberates Refactoring Excella Consulting
  • 31. In Test Code, Do Repeat Yourself ... Do Repeat Yourself Obstacle 4 Unhelpful … Reuse Repetition Coupling Excella Consulting
  • 32. 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
  • 33. 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
  • 34. Agenda 1 Motivation 2 Principles 3 Obstacles Excella Consulting - 34 -
  • 35. Of Course It’s Safe … After You Excella Consulting
  • 36. Further Discussion Any questions? Any comments? Excella Consulting
  • 37. Shameless Self Promotion Time! 40% off eBook at apress.com Use promo code: LIN340 Offer ends 6-Oct-2012 Excella Consulting
  • 38. Contact Me • Twitter: @ruthlesshelp • Email: stephen.ritchie@excella.com • Blog: http://ruthlesslyhelpful.net • LinkedIn: http://www.linkedin.com/in/sritchie Excella Consulting
  • 39. Slides and Examples • Slideshare: http://www.slideshare.net/ruthlesshelp • Github: http://github.com/ruthlesshelp Excella Consulting