SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
www.odd-e.com




      I hate unit testing!!!




Friday, 9 December, 11
Who am I?

                     • Name: Steven Mak
                     • Agile Coach at Odd-e
                     • Lives in Hong Kong
                     • Agile, TDD Coaching
                     • I love coding - Java, C/C++,
                         PHP, Perl, and some weird
                         ones
                     •   I speak English, Cantonese,
                         and Mandarin


                                                       2


Friday, 9 December, 11
3


Friday, 9 December, 11
I HATE UNIT TESTING!


   • Doesn’t catch many bugs
   • Still need to do integration tests
   • Waste time



                                                4


Friday, 9 December, 11
Need to test at integration
                              level anyway?




                               Is this what you mean by integration testing?


                                                                               5

Friday, 9 December, 11
How many tests do you need to cover
                       through system level tests?


                                                                                                       10
                                                                                                     states
                      Tests                                            5 interactions
                                                                                                                      5 interactions




                                                                              10                     5 interactions
                                                                                                                        10
                                                                            states                                    states


                                     • It would take 1000 (or more) tests to this simple system!
                                     • System Level Tests just cannot be thorough
                                                                                                                                       6
     Adapted from: http://www.renaissancesoftware.net/files/sglon/LondonScrumGathering-v1r0.key.pdf


Friday, 9 December, 11
The down side
                     • Tons of them to write
                     • False sense of security
                     • Integration tests are slow
                     • Hard to diagnose
                     • Brittle
                        - one change would trigger many test failures




                                                                        7

Friday, 9 December, 11
Test Automation Pyramid




                You are going to need some integration tests,
                but not in the way you do like unit tests.      8

Friday, 9 December, 11
Write good focused unit tests

        • Don’t test the platform.
        • When writing a single object to test with other
            collaborating objects, use interfaces for those
            other points. Interfaces are not the actual
            collaborating object.
        •   Leverage the interfaces so you don’t need to
            actually test the other objects.
        •   Test the single object to speak to itself, i.e.
            State Tests
        •   Create your focused Collaboration and
            Contract Tests.
                                                              http://b-speaking.blogspot.com/search/label/integration%20tests




                                                                                                                                9

Friday, 9 December, 11
Collaboration and Contract Tests

                     • Collaboration tests:
                        - Do I ask the collaborators the right questions?
                        - Can I handle the collaborators’ responses?
                     • Contract tests:
                        - Can the interface accept the question being asked of it?
                        - Can the interface supply the responses expected?




                                                                                     10

Friday, 9 December, 11
Example:
                                                              We are assuming that
      @Test                                                   compareTo() would return 1
      public void with_arguments(){                           if we pass in “Test”
      ! MyCollaborator c = mock(MyCollaborator.class);
      ! when(c.compareTo("Test")).thenReturn(1);
      ! assertEquals(1,a.doSomethingElse("Test"));
      }



      @Test
      public void compareToShouldReturnOne(){      We write a test for the real
      ! ! MyCollaborator c = new MyCollaborator(); MyCollaborator.compareTo()
      ! ! assertEquals(1,c.compareTo("Test"));
      }



      Contract tests are usually slow but tend to be
      stable. Often running just once a day is plenty                              11

Friday, 9 December, 11
Refactoring?

                                                                                        Code smells!

                                                                                        Code stinks!




                    It’s no fun writing unit test if you don’t spend time refactoring




                                                                                                       12

Friday, 9 December, 11
Why? How?
                                       opportunity for

                         refactoring
                                        amount of code
                                           smells

                              O               indicates          motivation
                                                                 developers
                                                          O
                                       amount of bad
                                          code
                                                              quick hacks


                                  # of bugs                           panic
                                                 time spend on
                                                    bug fixing
                                                                              13

Friday, 9 December, 11
Refactoring visualized
                            Without refactoring:


                Original program:



                Making changes:



                 More changes:




                                                   14

Friday, 9 December, 11
Refactoring visualized
                            Without refactoring:


                Original program:



                Making changes:



                 More changes:




                                                   14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:


                Original program:



                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!           14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:



                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!                               14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:
                                                                          Small change


                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!                                              14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:
                                                                          Small change


                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!                                              14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:
                                                                          Small change

                                                                          Refactor
                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!                                              14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:
                                                                          Small change

                                                                          Refactor
                Making changes:



                 More changes:




                         Cost of change
                         increases rapidly!                                              14

Friday, 9 December, 11
Refactoring visualized
                               Without refactoring:   With refactoring:


                Original program:
                                                                          Small change

                                                                          Refactor
                Making changes:

                                                                           Etc
                 More changes:




                         Cost of change                 Cost of change
                         increases rapidly!             not increases                    14

Friday, 9 December, 11
Refactoring based on unit testing




                                                             15

Friday, 9 December, 11
What to refactor?




                                             16


Friday, 9 December, 11
Beware of blocking
                • Individual Code Ownership?
                • Branching for long time?
                • Deadline pressure?
                  - Refactoring makes your code base easier to work on




                                                                         17


Friday, 9 December, 11
Time consuming?




                          Too busy fire fighting, but no time to write tests?




                                                                              18


Friday, 9 December, 11
Sustainability

       Traditional       Speculate   Code   Test   Debug

      development

Time                           vs




                                                           19

Friday, 9 December, 11
Time developers
                                                    do not notice
                         Sustainability              nor plan for



       Traditional       Speculate   Code   Test   Debug

      development

Time                           vs




                                                               19

Friday, 9 December, 11
Time developers
                                                         do not notice
                         Sustainability                   nor plan for



       Traditional       Speculate    Code     Test     Debug

      development

Time                             vs




       Test-driven       Spec
                                        Test and Code    Debug
      development        ulate



                                                                    19

Friday, 9 December, 11
Sustainability

       Traditional       Speculate    Code     Test     Debug

      development

Time                             vs
                                                           Feels
                                                           slower

       Test-driven       Spec
                                        Test and Code    Debug
      development        ulate



                                                                    19

Friday, 9 December, 11
We are tired of
                             delivering craps




                         Do you have confidence with your work
                                 before you deliver it?         20


Friday, 9 December, 11
Edsger Dijkstra
                         “Those who want really reliable
                         software will discover that they must
                         find means of avoiding the majority
                         of bugs to start with, and as a result,
                         the programming process will
                         become cheaper. If you want more
                         effective programmers, you will
                         discover that they should not waste
                         their time debugging, they should
                         not introduce the bugs to start with.”


                                                                   21

Friday, 9 December, 11
TDD Cycle
            Test

                         Implement

                                     Design




                          • Short
                          • Rhythmic
                          • Incremental
                          • Design-focused
                          • Disciplined
                                                          22

Friday, 9 December, 11
Oh, Our code was there already

                1. Identify change point
                2. Find test points
                3. Break dependencies
                4. Write tests
                5. Make changes and refactor




                           It is always harder to write unit tests
                                   after we wrote the code           23


Friday, 9 December, 11
Our code is too simple,
                            so we don’t need unit testing




                                      Our code is too complicated,
                                    so writing unit tests is too difficult




                         We don’t have problems at unit level

                                                                            24

Friday, 9 December, 11
Tests you write after the fact are
                             Defense or Justification
                • Test later = Test never
                • After-the-fact tests are written by someone
                     who is already vested in the code and
                     already knows how the problem was solved
                •    There’s just no way those tests can be
                     anywhere near as incisive as tests written
                     first




                • If you write the unit test after the fact, you
                     are not going to catch many bugs.


                                                                   25


Friday, 9 December, 11
Unit test is not just about testing




                                   Look at the design through unit tests


                                                                           26

Friday, 9 December, 11
Modularity                ==       Testability




                         Focus on tests first ensures modularity
                            and other good design principles      27

Friday, 9 December, 11
Design from the perspective of use
      rather than implementation

                                           28

Friday, 9 December, 11
It is always harder to write unit tests
                                            after we wrote the code

                • Debug-later-programming don’t consider testability in the first place
                • TDD guarantees testability, while you still need to know good design
                     principles
                •    Unit tests give you a safety net to try different design




                                                                                         29

Friday, 9 December, 11
When you find it hard to
                           write unit tests...
                     • Instantiating class instance that is hard to setup?
                        - What about using Factories?
                        - Have you think about Dependency Injection?
                     • Long methods?
                        - Does it have more than one responsibilities?
                     • Bare classes?
                        - Why not provide abstract base classes to support better mocking?
                        - Why clients need to know everything from this base class?
                           •   Interface Segregation Principle




                                                                                             30

Friday, 9 December, 11
TDD, The Professional Option
              •          Confidence and trust in the code

                          -   Treading the happy path

                          -   “If it doesn’t have to work, I can get it done a lot faster!”

                          -   “Cost of bug fixing is lower if it is found earlier”

              •          Encourages good design

                          -   Clean it up later

                          -   Experimenting different design

              •          Integration Testing

                          -   Making assumptions explicit

                                                                                              31

Friday, 9 December, 11
Resources


                         32

Friday, 9 December, 11
Agile Tour ShenZhen
                     • Tencent Building, Shenzhen (
                        - 20 Nov 2011
                        - Tencent Building, Kejizhongyi Avenue, Hi-techPark,Nanshan
                             District,Shenzhen.
                         -                              腾讯                   侧


                     • http://www.agiletour.cn
                     • Contact: steven@odd-e.com




                                                                                      33

Friday, 9 December, 11
I want to organise a group in
                          Hong Kong!


                     http://tinyurl.com/HKALSDN




                                                  34

Friday, 9 December, 11
Further readings
                     • Integration Tests are a Scam:
                        - http://www.jbrains.ca/series/integrated-tests-are-a-scam
                     • Integration Contract Tests:
                        - http://martinfowler.com/bliki/IntegrationContractTest.html
                     • Opportunistic Refactoring:
                        - http://martinfowler.com/bliki/OpportunisticRefactoring.html
                     • Demand Technical Excellence:
                        - http://www.renaissancesoftware.net/files/sglon/
                            LondonScrumGathering-v1r0.key.pdf
                     •   Clean Coder, by Robert Martin




                                                                                        35

Friday, 9 December, 11
Books - Technical Practices




                                                 36

Friday, 9 December, 11
Thank you :-)


     Steven Mak
     Email: steven@odd-e.com
                                         37


Friday, 9 December, 11

Más contenido relacionado

La actualidad más candente

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentMireia Sangalo
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
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
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit TestingShaun Abram
 
Unit testing
Unit testing Unit testing
Unit testing dubbu
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard partsShaun Abram
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NETPuneet Ghanshani
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonSeb Rose
 

La actualidad más candente (19)

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
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
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Unit testing
Unit testing Unit testing
Unit testing
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Nunit
NunitNunit
Nunit
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NET
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
 

Similar a Is this how you hate unit testing?

Seconf2011 database driven combinatorial testing
Seconf2011   database driven combinatorial testingSeconf2011   database driven combinatorial testing
Seconf2011 database driven combinatorial testingAaron Silverman
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grailswinkler1
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockJoseph Yoder
 
Pragmatic notdogmatictdd agile2012
Pragmatic notdogmatictdd   agile2012Pragmatic notdogmatictdd   agile2012
Pragmatic notdogmatictdd agile2012drewz lin
 
Test Driven Sysadmin
Test Driven SysadminTest Driven Sysadmin
Test Driven Sysadminjohanku
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
Are Your Tests Really Helping You?
Are Your Tests Really Helping You?Are Your Tests Really Helping You?
Are Your Tests Really Helping You?LB Denker
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-DrivenIan Truslove
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD Daniel Tracy
 
Morph your mindset for Continuous Delivery, Agile Roots 2014
Morph your mindset for Continuous Delivery,  Agile Roots 2014Morph your mindset for Continuous Delivery,  Agile Roots 2014
Morph your mindset for Continuous Delivery, Agile Roots 2014lisacrispin
 
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
 
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
 
Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Danny van Kasteel
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - WorkshopAnjana Somathilake
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development Amir Assad
 
The Test Case as Executable Example
The Test Case as Executable ExampleThe Test Case as Executable Example
The Test Case as Executable ExampleArie van Deursen
 

Similar a Is this how you hate unit testing? (20)

Seconf2011 database driven combinatorial testing
Seconf2011   database driven combinatorial testingSeconf2011   database driven combinatorial testing
Seconf2011 database driven combinatorial testing
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grails
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
 
Pragmatic notdogmatictdd agile2012
Pragmatic notdogmatictdd   agile2012Pragmatic notdogmatictdd   agile2012
Pragmatic notdogmatictdd agile2012
 
Test Driven Sysadmin
Test Driven SysadminTest Driven Sysadmin
Test Driven Sysadmin
 
Practical Guide to Unit Testing
Practical Guide to Unit TestingPractical Guide to Unit Testing
Practical Guide to Unit Testing
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Are Your Tests Really Helping You?
Are Your Tests Really Helping You?Are Your Tests Really Helping You?
Are Your Tests Really Helping You?
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD
 
Test Driven Development - Caleb Tutty
Test Driven Development - Caleb TuttyTest Driven Development - Caleb Tutty
Test Driven Development - Caleb Tutty
 
Morph your mindset for Continuous Delivery, Agile Roots 2014
Morph your mindset for Continuous Delivery,  Agile Roots 2014Morph your mindset for Continuous Delivery,  Agile Roots 2014
Morph your mindset for Continuous Delivery, Agile Roots 2014
 
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...
 
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
 
Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?Unit Test Lab - Why Write Unit Tests?
Unit Test Lab - Why Write Unit Tests?
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - Workshop
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
The Test Case as Executable Example
The Test Case as Executable ExampleThe Test Case as Executable Example
The Test Case as Executable Example
 

Más de Steven Mak

Continuous Security Testing
Continuous Security TestingContinuous Security Testing
Continuous Security TestingSteven Mak
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing toolsSteven Mak
 
Adopting technical practices 2013
Adopting technical practices 2013Adopting technical practices 2013
Adopting technical practices 2013Steven Mak
 
100 doors kata solution
100 doors kata solution100 doors kata solution
100 doors kata solutionSteven Mak
 
Bossless companies
Bossless companiesBossless companies
Bossless companiesSteven Mak
 
Driving Quality with TDD
Driving Quality with TDDDriving Quality with TDD
Driving Quality with TDDSteven Mak
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code SmellSteven Mak
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDDSteven Mak
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentSteven Mak
 
Essential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionEssential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionSteven Mak
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in PracticeSteven Mak
 

Más de Steven Mak (11)

Continuous Security Testing
Continuous Security TestingContinuous Security Testing
Continuous Security Testing
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing tools
 
Adopting technical practices 2013
Adopting technical practices 2013Adopting technical practices 2013
Adopting technical practices 2013
 
100 doors kata solution
100 doors kata solution100 doors kata solution
100 doors kata solution
 
Bossless companies
Bossless companiesBossless companies
Bossless companies
 
Driving Quality with TDD
Driving Quality with TDDDriving Quality with TDD
Driving Quality with TDD
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code Smell
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDD
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven Development
 
Essential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionEssential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile Adoption
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in Practice
 

Último

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 

Último (20)

201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 

Is this how you hate unit testing?

  • 1. www.odd-e.com I hate unit testing!!! Friday, 9 December, 11
  • 2. Who am I? • Name: Steven Mak • Agile Coach at Odd-e • Lives in Hong Kong • Agile, TDD Coaching • I love coding - Java, C/C++, PHP, Perl, and some weird ones • I speak English, Cantonese, and Mandarin 2 Friday, 9 December, 11
  • 4. I HATE UNIT TESTING! • Doesn’t catch many bugs • Still need to do integration tests • Waste time 4 Friday, 9 December, 11
  • 5. Need to test at integration level anyway? Is this what you mean by integration testing? 5 Friday, 9 December, 11
  • 6. How many tests do you need to cover through system level tests? 10 states Tests 5 interactions 5 interactions 10 5 interactions 10 states states • It would take 1000 (or more) tests to this simple system! • System Level Tests just cannot be thorough 6 Adapted from: http://www.renaissancesoftware.net/files/sglon/LondonScrumGathering-v1r0.key.pdf Friday, 9 December, 11
  • 7. The down side • Tons of them to write • False sense of security • Integration tests are slow • Hard to diagnose • Brittle - one change would trigger many test failures 7 Friday, 9 December, 11
  • 8. Test Automation Pyramid You are going to need some integration tests, but not in the way you do like unit tests. 8 Friday, 9 December, 11
  • 9. Write good focused unit tests • Don’t test the platform. • When writing a single object to test with other collaborating objects, use interfaces for those other points. Interfaces are not the actual collaborating object. • Leverage the interfaces so you don’t need to actually test the other objects. • Test the single object to speak to itself, i.e. State Tests • Create your focused Collaboration and Contract Tests. http://b-speaking.blogspot.com/search/label/integration%20tests 9 Friday, 9 December, 11
  • 10. Collaboration and Contract Tests • Collaboration tests: - Do I ask the collaborators the right questions? - Can I handle the collaborators’ responses? • Contract tests: - Can the interface accept the question being asked of it? - Can the interface supply the responses expected? 10 Friday, 9 December, 11
  • 11. Example: We are assuming that @Test compareTo() would return 1 public void with_arguments(){ if we pass in “Test” ! MyCollaborator c = mock(MyCollaborator.class); ! when(c.compareTo("Test")).thenReturn(1); ! assertEquals(1,a.doSomethingElse("Test")); } @Test public void compareToShouldReturnOne(){ We write a test for the real ! ! MyCollaborator c = new MyCollaborator(); MyCollaborator.compareTo() ! ! assertEquals(1,c.compareTo("Test")); } Contract tests are usually slow but tend to be stable. Often running just once a day is plenty 11 Friday, 9 December, 11
  • 12. Refactoring? Code smells! Code stinks! It’s no fun writing unit test if you don’t spend time refactoring 12 Friday, 9 December, 11
  • 13. Why? How? opportunity for refactoring amount of code smells O indicates motivation developers O amount of bad code quick hacks # of bugs panic time spend on bug fixing 13 Friday, 9 December, 11
  • 14. Refactoring visualized Without refactoring: Original program: Making changes: More changes: 14 Friday, 9 December, 11
  • 15. Refactoring visualized Without refactoring: Original program: Making changes: More changes: 14 Friday, 9 December, 11
  • 16. Refactoring visualized Without refactoring: Original program: Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 17. Refactoring visualized Without refactoring: With refactoring: Original program: Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 18. Refactoring visualized Without refactoring: With refactoring: Original program: Small change Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 19. Refactoring visualized Without refactoring: With refactoring: Original program: Small change Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 20. Refactoring visualized Without refactoring: With refactoring: Original program: Small change Refactor Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 21. Refactoring visualized Without refactoring: With refactoring: Original program: Small change Refactor Making changes: More changes: Cost of change increases rapidly! 14 Friday, 9 December, 11
  • 22. Refactoring visualized Without refactoring: With refactoring: Original program: Small change Refactor Making changes: Etc More changes: Cost of change Cost of change increases rapidly! not increases 14 Friday, 9 December, 11
  • 23. Refactoring based on unit testing 15 Friday, 9 December, 11
  • 24. What to refactor? 16 Friday, 9 December, 11
  • 25. Beware of blocking • Individual Code Ownership? • Branching for long time? • Deadline pressure? - Refactoring makes your code base easier to work on 17 Friday, 9 December, 11
  • 26. Time consuming? Too busy fire fighting, but no time to write tests? 18 Friday, 9 December, 11
  • 27. Sustainability Traditional Speculate Code Test Debug development Time vs 19 Friday, 9 December, 11
  • 28. Time developers do not notice Sustainability nor plan for Traditional Speculate Code Test Debug development Time vs 19 Friday, 9 December, 11
  • 29. Time developers do not notice Sustainability nor plan for Traditional Speculate Code Test Debug development Time vs Test-driven Spec Test and Code Debug development ulate 19 Friday, 9 December, 11
  • 30. Sustainability Traditional Speculate Code Test Debug development Time vs Feels slower Test-driven Spec Test and Code Debug development ulate 19 Friday, 9 December, 11
  • 31. We are tired of delivering craps Do you have confidence with your work before you deliver it? 20 Friday, 9 December, 11
  • 32. Edsger Dijkstra “Those who want really reliable software will discover that they must find means of avoiding the majority of bugs to start with, and as a result, the programming process will become cheaper. If you want more effective programmers, you will discover that they should not waste their time debugging, they should not introduce the bugs to start with.” 21 Friday, 9 December, 11
  • 33. TDD Cycle Test Implement Design • Short • Rhythmic • Incremental • Design-focused • Disciplined 22 Friday, 9 December, 11
  • 34. Oh, Our code was there already 1. Identify change point 2. Find test points 3. Break dependencies 4. Write tests 5. Make changes and refactor It is always harder to write unit tests after we wrote the code 23 Friday, 9 December, 11
  • 35. Our code is too simple, so we don’t need unit testing Our code is too complicated, so writing unit tests is too difficult We don’t have problems at unit level 24 Friday, 9 December, 11
  • 36. Tests you write after the fact are Defense or Justification • Test later = Test never • After-the-fact tests are written by someone who is already vested in the code and already knows how the problem was solved • There’s just no way those tests can be anywhere near as incisive as tests written first • If you write the unit test after the fact, you are not going to catch many bugs. 25 Friday, 9 December, 11
  • 37. Unit test is not just about testing Look at the design through unit tests 26 Friday, 9 December, 11
  • 38. Modularity == Testability Focus on tests first ensures modularity and other good design principles 27 Friday, 9 December, 11
  • 39. Design from the perspective of use rather than implementation 28 Friday, 9 December, 11
  • 40. It is always harder to write unit tests after we wrote the code • Debug-later-programming don’t consider testability in the first place • TDD guarantees testability, while you still need to know good design principles • Unit tests give you a safety net to try different design 29 Friday, 9 December, 11
  • 41. When you find it hard to write unit tests... • Instantiating class instance that is hard to setup? - What about using Factories? - Have you think about Dependency Injection? • Long methods? - Does it have more than one responsibilities? • Bare classes? - Why not provide abstract base classes to support better mocking? - Why clients need to know everything from this base class? • Interface Segregation Principle 30 Friday, 9 December, 11
  • 42. TDD, The Professional Option • Confidence and trust in the code - Treading the happy path - “If it doesn’t have to work, I can get it done a lot faster!” - “Cost of bug fixing is lower if it is found earlier” • Encourages good design - Clean it up later - Experimenting different design • Integration Testing - Making assumptions explicit 31 Friday, 9 December, 11
  • 43. Resources 32 Friday, 9 December, 11
  • 44. Agile Tour ShenZhen • Tencent Building, Shenzhen ( - 20 Nov 2011 - Tencent Building, Kejizhongyi Avenue, Hi-techPark,Nanshan District,Shenzhen. - 腾讯 侧 • http://www.agiletour.cn • Contact: steven@odd-e.com 33 Friday, 9 December, 11
  • 45. I want to organise a group in Hong Kong! http://tinyurl.com/HKALSDN 34 Friday, 9 December, 11
  • 46. Further readings • Integration Tests are a Scam: - http://www.jbrains.ca/series/integrated-tests-are-a-scam • Integration Contract Tests: - http://martinfowler.com/bliki/IntegrationContractTest.html • Opportunistic Refactoring: - http://martinfowler.com/bliki/OpportunisticRefactoring.html • Demand Technical Excellence: - http://www.renaissancesoftware.net/files/sglon/ LondonScrumGathering-v1r0.key.pdf • Clean Coder, by Robert Martin 35 Friday, 9 December, 11
  • 47. Books - Technical Practices 36 Friday, 9 December, 11
  • 48. Thank you :-) Steven Mak Email: steven@odd-e.com 37 Friday, 9 December, 11