SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
Real Developers Don’t Need Unit Tests




                        Mythbusting TDD
So who is this guy, anyway?
  John Ferguson Smart
   CEO Wakaleo Consulting
   Consultant, Trainer, Mentor, Author,...
So who is this guy, anyway?
  John Ferguson Smart
   CEO Wakaleo Consulting
   Consultant, Trainer, Mentor, Author,...
So who is this guy, anyway?
  Java Power Tools Bootcamp
  maven            Hudson
                 JUnit




                          London
                     January 24-28 2011
Introduction
  Real Developers Don’t Need Unit Tests
      Bugs?




                 Chuck Norris’s code doesn’t have bugs




           His code always work. ALWAYS.
Introduction
  Real Developers Don’t Need Unit Tests
      Bugs?
    Emergent design?




                        Chuck Norris’s code is perfectly
                         designed the first time round




           His favorite design pattern is the
                  Roundhouse Kick
Introduction
  Real Developers Don’t Need Unit Tests
      Bugs?
    Emergent design?
     Technical documentation?


                        Chuck Norris doesn’t need
                         technical documentation




            He just stares down the code until it
           tells him everything he wants to know
Introduction
  Real Developers Don’t Need Unit Tests
      Bugs?
    Emergent design?
     Technical documentation?
        Executable requirements?


                         Chuck Norris doesn’t need
                       requirements to be executable




          He can execute whatever he wants
Introduction
  Real Developers Don’t Need Unit Tests
      Bugs?
    Emergent design?
     Technical documentation?
        Executable requirements?
             Acceptance Tests?


                         Chuck Norris doesn’t need
                             acceptance tests




          Everything Chuck does is acceptable
Introduction
  Real Developers Don’t Need Unit Tests




             OK, so Chuck Norris doesn’t need Unit Tests




              But what about the rest of us?
TDD Basics
  TDD is not about writing tests




              So what is this TDD thing, anyway?
TDD Basics
  TDD in a nutshell...




               “Red...Green...Refactor”
TDD Basics
  TDD in a nutshell...




               “The code your code could smell like”
TDD Basics
  TDD in a nutshell...




              Always tidy up after you play...
Stay On Target
     Stay focused on the requirements
        User Story 1 - Transfer funds
As a bank client
I want to withdraw funds from my current account
So that I can buy beer

         User Story 1 - Acceptance Tests

  - Cash withdrawal should deduct sum from balance
  - Client cannot withdraw if insufficient funds
  - Client cannot withdraw if account blocked
  ...
      @Test
      public void aCashWithdrawalShouldDeductSumFromBalance() {
          Account account = new Account();
          account.makeDeposit(100);
          account.makeCashWithdraw(60);
          assertThat(account.getBalance(), is(40));
      }
Executable Requirements
     Good tests are ‘executable requirements’
        User Story 1 - Transfer funds
As a bank client
I want to withdraw funds from my current account
So that I can buy beer

         User Story 1 - Acceptance Tests

  - Cash withdrawal should deduct sum from balance
  - Client cannot withdraw if insufficient funds
  - Client cannot withdraw if account blocked
  ...
      @Test
      public void aCashWithdrawalShouldDeductSumFromBalance() {
          Account account = new Account();
          account.makeDeposit(100);
          account.makeCashWithdraw(60);
          assertThat(account.getBalance(), is(40));
      }
Know where you’re at
     Know what requirements are done
        User Story 1 - Transfer funds
As a bank client
I want to withdraw funds from my current account
So that I can buy beer

         User Story 1 - Acceptance Tests

  - Cash withdrawal should deduct sum from balance
  - Client cannot withdraw if insufficient funds
  - Client cannot withdraw if account blocked
  ...
Safety net
  Refactor with confidence
Better-designed code
  Testable code is well-designed code
Not just for green fields
  Improve your legacy code base
TDD for unbelievers


                So TDD is the answer to all my problems?


                  No, sorry, TDD is not a Silver Bullet


 You still have to use your brain
   Also use other design activities (domain modeling, DDD,...)
 TDD is not applicable everywhere
   Highly visual coding, ‘know it when you see it’ stuff,...
 TDD works best if you have a vision
TDD for unbelievers

               But how can I write tests if I don’t know what the code looks like?


                     How can you write code when you can’t express what it
                                          should do?


   “Write code for others as you would have them write code for you”
                                                               - Some agile dude
TDD for unbelievers


                           I don’t have time to write tests

                   But you have time to fix the code afterwards, right?


       “I can get it done much faster if it doesn’t have to work”
                                                       - Kent Beck (paraphrased)



 New TDDers will take maybe 20-30% longer
 Experienced TDD developers don’t spend much (if any)
 more time coding
 But the code is of much higher quality
TDD for unbelievers


               But I'm writing more test code than application code!

                 Sure, writing tests is part of the process


 You will write lots of tests...
 ...but your code will be more focused and more accurate
TDD for unbelievers


                  My tests break whenever I change my code

                   Try to test the behaviour, not the implementation


 Validate behaviour, don’t verify implementation
TDD for unbelievers


             Our tests are too hard and take too much time to keep up to date

                          Treat your test code as production code


 Be wary of test maintenance overhead
   Test code is not second-class code
   Refactor to keep your test code maintainable
   Avoid technical debt
TDD for unbelievers


                  I found a bug in the production code. TDD doesn’t work.

                               see “TDD is not a Silver Bullet”


 You still need your testers!
   You can still make mistakes...
   ...but they are easier to isolate and to fix
   If you find a bug, just add another test to reproduce it, then fix it!
TDD for unbelievers

              I’ve heard TDD encourages sloppy design. Isn't it better to have a
                   general vision of the problem before coding the solution?"

                    Sometimes, yes. That's what the refactoring phase is for.


 TDD does not preclude initial high-level design
   Brainstorm a high-level design approach
   Define a common well-known domain language
   Use an ‘Iteration 0’ and spikes
   Don’t be afraid to refactor
 TDD works better when you have a vision
TDD for unbelievers

              I use a database/network/web service... and TDD-style unit tests
                               can't test it. TDD doesn't work

                               You will need integration tests too


 Unit tests when you can, integrations tests when you must
   Integration tests for system boundaries
   Mock out these boundary classes for the rest of your tests
TDD for unbelievers


                     Our BAs and product owners aren’t buying this TDD stuff

                                  Try putting them into the feedback loop


 Acceptance-Test Driven Development is about communication
   BDD help BAs and POs participate in writing executable requirements
   scenario "A cell with less than 2 live neighbours should die", {
   	   given "Given a cell with no live neighbours",
   	   when "a new generation is generated",
   	   then "that cell will have died"
   }
TDD for unbelievers


                     Our BAs and product owners aren’t buying this TDD stuff

                                  Try putting them into the feedback loop


 Acceptance-Test Driven Development is about communication
   BDD help BAs and POs participate in writing executable requirements
   scenario "A cell with less than 2 live neighbours should die", {
   	   given "Given a cell with no live neighbours", {
   	   	   initialGrid = ""...
   	   	                   .*.
   	   	                   ...""
   	   	   theUniverse = new Universe(seededWith(initialGrid));
   	   }
   	   when "a new generation is generated", {
   	   	   theUniverse.createNextGeneration()
   	   }
   	   then "that cell will have died", {
   	   	   theUniverse.grid.shouldBe ""...
     	 	   	   	   	  	   	   	  	     ...
   	   	   	   	   	  	   	   	  	     ...""
   	   }
   }
TDD for unbelievers


                     Our BAs and product owners aren’t buying this TDD stuff

                                  Try putting them into the feedback loop


 Acceptance-Test Driven Development is about communication
   BDD help BAs and POs participate in writing executable requirements
   Given a living cell with no live neighbours like this
   ...
   .*.
   ...
   When a new generation is generated
   then the grid should look like this:
   ...
   ...
   ...
TDD for unbelievers

            Many BDD tools also have great reporting features




                                      Test results summary

                                          Unimplemented stories



                                              Failed stories
TDD for unbelievers

             Many BDD tools have great reporting features

                                                 Test results summary




                                                      Test failure details




                                              Unimplemented stories
TDD for unbelievers


             “I’ve tried TDD, but I soon lapse back into my old code-first habits”

                       TDD takes practice and know-how


 Unit tests when you can, integrations tests when you must
   Learn about TDD - read books on TDD practices
   Do pair program with someone who knows TDD
   Participate in and organize coding dojos
   <blatant plug>Training/mentoring</blatant plug>
Conclusion
  Real Developers Don’t Need Unit Tests?




              So maybe Chuck should be writing
                    unit tests after all...




                I agree. You go talk to him
Enjoy your quiche!



        John Ferguson Smart
            Wakaleo Consulting Ltd.
                 http://www.wakaleo.com
         Email: john.smart@wakaleo.com
                         Twitter: wakaleo

Mais conteúdo relacionado

Mais procurados

TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereDaniel Davis
 
Why Test Driven Development?
Why Test Driven Development?Why Test Driven Development?
Why Test Driven Development?Naresh Jain
 
Testers and developers think differently
Testers and developers think differentlyTesters and developers think differently
Testers and developers think differentlyNuthan Kumar
 
Pragmatic notdogmatictdd
Pragmatic notdogmatictddPragmatic notdogmatictdd
Pragmatic notdogmatictddJoseph Yoder
 
Lessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorialLessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorialAlan Richardson
 
Test driven development
Test driven developmentTest driven development
Test driven developmentShalabh Saxena
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect coupleStephen Tucker
 
Using tests and mocks to drive the design of software
Using tests and mocks to drive the design of softwareUsing tests and mocks to drive the design of software
Using tests and mocks to drive the design of softwareAttila Magyar
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Zohirul Alam Tiemoon
 
Refactoring AOMs For AgilePT2010
Refactoring AOMs For AgilePT2010Refactoring AOMs For AgilePT2010
Refactoring AOMs For AgilePT2010Joseph Yoder
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 

Mais procurados (18)

Atdd half day_new_1_up
Atdd half day_new_1_upAtdd half day_new_1_up
Atdd half day_new_1_up
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & Where
 
Why Test Driven Development?
Why Test Driven Development?Why Test Driven Development?
Why Test Driven Development?
 
Testers and developers think differently
Testers and developers think differentlyTesters and developers think differently
Testers and developers think differently
 
Journey of atdd
Journey of atddJourney of atdd
Journey of atdd
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Pragmatic notdogmatictdd
Pragmatic notdogmatictddPragmatic notdogmatictdd
Pragmatic notdogmatictdd
 
ATDD in practice
ATDD in practiceATDD in practice
ATDD in practice
 
Lean agile pt
Lean  agile ptLean  agile pt
Lean agile pt
 
Oxente BDD
Oxente BDDOxente BDD
Oxente BDD
 
Lessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorialLessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorial
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect couple
 
Using tests and mocks to drive the design of software
Using tests and mocks to drive the design of softwareUsing tests and mocks to drive the design of software
Using tests and mocks to drive the design of software
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
Refactoring AOMs For AgilePT2010
Refactoring AOMs For AgilePT2010Refactoring AOMs For AgilePT2010
Refactoring AOMs For AgilePT2010
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 

Semelhante a Real developers-dont-need-unit-tests

Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
 
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
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
Test Driven Development: More Development Than Ever
Test Driven Development: More Development Than EverTest Driven Development: More Development Than Ever
Test Driven Development: More Development Than EverKiryl Baranoshnik
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Bdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propriBdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propriCommit University
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingCamille Bell
 
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NETNDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NETjbandi
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentjakubkoci
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit TestingShaun Abram
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Tdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in GermanyTdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in GermanyOrlovsky Consulting GbR
 

Semelhante a Real developers-dont-need-unit-tests (20)

Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
Real Developers Don't Need Unit Tests
Real Developers Don't Need Unit TestsReal Developers Don't Need Unit Tests
Real Developers Don't Need Unit Tests
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
Gateway to Agile: XP and BDD
Gateway to Agile: XP and BDD Gateway to Agile: XP and BDD
Gateway to Agile: XP and BDD
 
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)
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
TDD in Agile
TDD in AgileTDD in Agile
TDD in Agile
 
Test Driven Development: More Development Than Ever
Test Driven Development: More Development Than EverTest Driven Development: More Development Than Ever
Test Driven Development: More Development Than Ever
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Bdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propriBdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propri
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About Testing
 
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NETNDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Tdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in GermanyTdd2018 state of the software quality in Germany
Tdd2018 state of the software quality in Germany
 

Mais de John Ferguson Smart Limited

My Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosMy Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosJohn Ferguson Smart Limited
 
Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...John Ferguson Smart Limited
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceJohn Ferguson Smart Limited
 
Sustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplaySustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplayJohn Ferguson Smart Limited
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceJohn Ferguson Smart Limited
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...John Ferguson Smart Limited
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...John Ferguson Smart Limited
 
Screenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingScreenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingJohn Ferguson Smart Limited
 
All the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesAll the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesJohn Ferguson Smart Limited
 
It's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersIt's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersJohn Ferguson Smart Limited
 

Mais de John Ferguson Smart Limited (20)

My Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosMy Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin Scenarios
 
Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a difference
 
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANTBE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
 
Sustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplaySustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and Screenplay
 
Feature Mapping Workshop
Feature Mapping WorkshopFeature Mapping Workshop
Feature Mapping Workshop
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a difference
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
Shift left-devoxx-pl
Shift left-devoxx-plShift left-devoxx-pl
Shift left-devoxx-pl
 
Screenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingScreenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testing
 
Cucumber and Spock Primer
Cucumber and Spock PrimerCucumber and Spock Primer
Cucumber and Spock Primer
 
All the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesAll the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practices
 
CukeUp 2016 Agile Product Planning Workshop
CukeUp 2016 Agile Product Planning WorkshopCukeUp 2016 Agile Product Planning Workshop
CukeUp 2016 Agile Product Planning Workshop
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
Serenity and the Journey Pattern
Serenity and the Journey PatternSerenity and the Journey Pattern
Serenity and the Journey Pattern
 
BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!
 
BDD-Driven Microservices
BDD-Driven MicroservicesBDD-Driven Microservices
BDD-Driven Microservices
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
It's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersIt's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for Testers
 

Real developers-dont-need-unit-tests

  • 1. Real Developers Don’t Need Unit Tests Mythbusting TDD
  • 2. So who is this guy, anyway? John Ferguson Smart CEO Wakaleo Consulting Consultant, Trainer, Mentor, Author,...
  • 3. So who is this guy, anyway? John Ferguson Smart CEO Wakaleo Consulting Consultant, Trainer, Mentor, Author,...
  • 4. So who is this guy, anyway? Java Power Tools Bootcamp maven Hudson JUnit London January 24-28 2011
  • 5. Introduction Real Developers Don’t Need Unit Tests Bugs? Chuck Norris’s code doesn’t have bugs His code always work. ALWAYS.
  • 6. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Chuck Norris’s code is perfectly designed the first time round His favorite design pattern is the Roundhouse Kick
  • 7. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Chuck Norris doesn’t need technical documentation He just stares down the code until it tells him everything he wants to know
  • 8. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Chuck Norris doesn’t need requirements to be executable He can execute whatever he wants
  • 9. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Acceptance Tests? Chuck Norris doesn’t need acceptance tests Everything Chuck does is acceptable
  • 10. Introduction Real Developers Don’t Need Unit Tests OK, so Chuck Norris doesn’t need Unit Tests But what about the rest of us?
  • 11. TDD Basics TDD is not about writing tests So what is this TDD thing, anyway?
  • 12. TDD Basics TDD in a nutshell... “Red...Green...Refactor”
  • 13. TDD Basics TDD in a nutshell... “The code your code could smell like”
  • 14. TDD Basics TDD in a nutshell... Always tidy up after you play...
  • 15. Stay On Target Stay focused on the requirements User Story 1 - Transfer funds As a bank client I want to withdraw funds from my current account So that I can buy beer User Story 1 - Acceptance Tests - Cash withdrawal should deduct sum from balance - Client cannot withdraw if insufficient funds - Client cannot withdraw if account blocked ... @Test public void aCashWithdrawalShouldDeductSumFromBalance() { Account account = new Account(); account.makeDeposit(100); account.makeCashWithdraw(60); assertThat(account.getBalance(), is(40)); }
  • 16. Executable Requirements Good tests are ‘executable requirements’ User Story 1 - Transfer funds As a bank client I want to withdraw funds from my current account So that I can buy beer User Story 1 - Acceptance Tests - Cash withdrawal should deduct sum from balance - Client cannot withdraw if insufficient funds - Client cannot withdraw if account blocked ... @Test public void aCashWithdrawalShouldDeductSumFromBalance() { Account account = new Account(); account.makeDeposit(100); account.makeCashWithdraw(60); assertThat(account.getBalance(), is(40)); }
  • 17. Know where you’re at Know what requirements are done User Story 1 - Transfer funds As a bank client I want to withdraw funds from my current account So that I can buy beer User Story 1 - Acceptance Tests - Cash withdrawal should deduct sum from balance - Client cannot withdraw if insufficient funds - Client cannot withdraw if account blocked ...
  • 18. Safety net Refactor with confidence
  • 19. Better-designed code Testable code is well-designed code
  • 20. Not just for green fields Improve your legacy code base
  • 21. TDD for unbelievers So TDD is the answer to all my problems? No, sorry, TDD is not a Silver Bullet You still have to use your brain Also use other design activities (domain modeling, DDD,...) TDD is not applicable everywhere Highly visual coding, ‘know it when you see it’ stuff,... TDD works best if you have a vision
  • 22. TDD for unbelievers But how can I write tests if I don’t know what the code looks like? How can you write code when you can’t express what it should do? “Write code for others as you would have them write code for you” - Some agile dude
  • 23. TDD for unbelievers I don’t have time to write tests But you have time to fix the code afterwards, right? “I can get it done much faster if it doesn’t have to work” - Kent Beck (paraphrased) New TDDers will take maybe 20-30% longer Experienced TDD developers don’t spend much (if any) more time coding But the code is of much higher quality
  • 24. TDD for unbelievers But I'm writing more test code than application code! Sure, writing tests is part of the process You will write lots of tests... ...but your code will be more focused and more accurate
  • 25. TDD for unbelievers My tests break whenever I change my code Try to test the behaviour, not the implementation Validate behaviour, don’t verify implementation
  • 26. TDD for unbelievers Our tests are too hard and take too much time to keep up to date Treat your test code as production code Be wary of test maintenance overhead Test code is not second-class code Refactor to keep your test code maintainable Avoid technical debt
  • 27. TDD for unbelievers I found a bug in the production code. TDD doesn’t work. see “TDD is not a Silver Bullet” You still need your testers! You can still make mistakes... ...but they are easier to isolate and to fix If you find a bug, just add another test to reproduce it, then fix it!
  • 28. TDD for unbelievers I’ve heard TDD encourages sloppy design. Isn't it better to have a general vision of the problem before coding the solution?" Sometimes, yes. That's what the refactoring phase is for. TDD does not preclude initial high-level design Brainstorm a high-level design approach Define a common well-known domain language Use an ‘Iteration 0’ and spikes Don’t be afraid to refactor TDD works better when you have a vision
  • 29. TDD for unbelievers I use a database/network/web service... and TDD-style unit tests can't test it. TDD doesn't work You will need integration tests too Unit tests when you can, integrations tests when you must Integration tests for system boundaries Mock out these boundary classes for the rest of your tests
  • 30. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements scenario "A cell with less than 2 live neighbours should die", { given "Given a cell with no live neighbours", when "a new generation is generated", then "that cell will have died" }
  • 31. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements scenario "A cell with less than 2 live neighbours should die", { given "Given a cell with no live neighbours", { initialGrid = ""... .*. ..."" theUniverse = new Universe(seededWith(initialGrid)); } when "a new generation is generated", { theUniverse.createNextGeneration() } then "that cell will have died", { theUniverse.grid.shouldBe ""... ... ..."" } }
  • 32. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements Given a living cell with no live neighbours like this ... .*. ... When a new generation is generated then the grid should look like this: ... ... ...
  • 33. TDD for unbelievers Many BDD tools also have great reporting features Test results summary Unimplemented stories Failed stories
  • 34. TDD for unbelievers Many BDD tools have great reporting features Test results summary Test failure details Unimplemented stories
  • 35. TDD for unbelievers “I’ve tried TDD, but I soon lapse back into my old code-first habits” TDD takes practice and know-how Unit tests when you can, integrations tests when you must Learn about TDD - read books on TDD practices Do pair program with someone who knows TDD Participate in and organize coding dojos <blatant plug>Training/mentoring</blatant plug>
  • 36. Conclusion Real Developers Don’t Need Unit Tests? So maybe Chuck should be writing unit tests after all... I agree. You go talk to him
  • 37. Enjoy your quiche! John Ferguson Smart Wakaleo Consulting Ltd. http://www.wakaleo.com Email: john.smart@wakaleo.com Twitter: wakaleo