SlideShare a Scribd company logo
Test Driven


u           Development
                        andaid!


                  f
                 Gettin gP
        Rowan Merewood
Software Eng. / Team Lead
                 Ibuildings
WHO AM I?

Software Engineer &
Technical Team Lead
at Ibuildings UK

  I want to write good code
      and earn a living


   @rowan_m
                      m
Not ?
WHO AM I?




s
               i-am-not-a
             Cconsultant
            well-maybe-a-little
Not ?
WHO AM I?




s
             i-am-not
            selling-a
               book
Not ?
WHO AM I?




s
             i-am-not
            a-slave-to
            one=method
THE GOOD




                    @
Clean code, smart devs
  Latest technology
 Building your career

Elitist / Intimidating?



              DIFFERENT SITUATIONS
THE BAD




                     g
   Disgusting code
   Devs don't care
   Career dead-end

Changes break the app.
  Always bug-fixing


             DIFFERENT SITUATIONS
THE UGLY




                    c
 Good tests are hard
Writing tests takes time
     Time is money

 You're not an expert
        (yet...)


              DIFFERENT SITUATIONS
WHAT IS TDD?


1.Decide what you want to do
2.Write a test to show it working
3.Run the test and watch it fail
4.Write just enough code to pass the test
5.Re-run the test (and test suite)
6.Refactor (refine/improve)
7.Re-run tests
8.Repeat
WHAT IS TDD?


simplify
                  RED




H                GREEN


               REFACTOR
WHY IS THIS HARD?




l
 Do you know what
     you want

      before

    you code it?
WHY IS THIS HARD?




l   Does your client
      know what
      they want?

            Ever?
Train yourself to think like a scientist




1.Hypothesis
2.Repeatable Experiment
3.Conclusions
                             ]
ninja
  Train yourself to think like a scientist




                                  ]
            Kata
1.Hypothesis terally: "form")
  ( 型 or 形 , li
2.Repeatable movements
       A set of Experiment
3.Conclusionsain and again
    you repeat ag
                          ctly.
    un til can do it perfe



                                  Ninja weapon
!
DAVE THOMAS

 co-author of
The Pragmatic
 Programmer

                      Code Kata
                http://code
                            kata.pragpro
                                        g.co   m/
ROY OSHEROVE - TDD Kata
              http://osherove.com/tdd-kata-1/



      Create a simple String calculator
  with a method int Add(string numbers)


 The method can take 0, 1 or 2 numbers,
        and will return their sum
  (for an empty string it will return 0)
      for example “” or “1” or “1,2”
.
ROY OSHEROVE - TDD Kata




                     demo
Now you're an expert...


                    warning

Do not assume you can
just start to do this
in your project            D
DON'T BE A HERO


Introduce tests all at once...

●
    You will miss your deadline
●
    Your tests will not be maintained
●
    Your team will hate you
DIFFERENT APPROACHES


      Force tests
     on your client

    Make your client
     want the tests   L
FORCING TESTS




to your estimates.

Do not compromise
your principles.
                     L
Add a fixed percentage
SELLING TESTS




in creating tests.

Make the tests
a deliverable.
                       L
Use tests to define 'done'.

Involve the client
SELLING TESTS




Involve the client
in creating tests.

Make the tests
a deliverable.
                       L
Use tests to define 'done'.
                     Fitnesse Framework
                     http://fitnesse.org/
SELLING TESTS




Involve the client
in creating tests.

Make the tests
a deliverable.
                        L
Use tests to define 'done'.
                      Fitnesse Framework
                      http://fitnesse.org/


                           Selenium
                     http://seleniumhq.org/
DON'T BELIEVE THE HYPE


Make sure you don't over-promise.

Make sure you have the
infrastructure and skills

NO SILVER BULLETS
v
     INFRASTRUCTURE




1.Unit Testing
2.Acceptance Testing
3.Automated Deployment
4.Continuous Integration
5.Issue Tracking
Unit/Acceptanc
provides the tec
1.Unit Testing
                v
     INFRASTRUCTURE



                e testing
                hnical base


2.Acceptance Testing
3.Automated Deployment
4.Continuous Integration
5.Issue Tracking
Unit/
    Au s          v
      INFRASTRUCTURE



                   e testing
         Acceptanc eployment
            ate t d
        tomthe d echnical base
 provide a quick test env.
1.Unitows
    all Testing
2.Acceptance Testing
3.Automated Deployment
4.Continuous Integration
5.Issue Tracking
Unit/
    Au s    ate t dv
      INFRASTRUCTURE



                    e testing
         Acceptanc eployment
        tomthe d echnical rbasen
 provide ntinuouckIte
       Co s a qui
1.Unitow
        makes pr
                  s    eg atio
                     ntst env.
    all Testing ogress visible
2.Acceptance Testing
3.Automated Deployment
4.Continuous Integration
5.Issue Tracking
INFRASTRUCTURE




  Unit/
    Au s    ate t d
       Co s a qui
                  s v
                    e testing
         Acceptanc eployment
        tomthe d echnical rbasen
 provide ntinuouckIte
                        eg atio
                     ntst env.
                       ingviallows
1.UnitowIssue Traress sible
    all Testing og ck
        makes pr
2.Acceptance rting on TDD
            repo Testing
3.Automated Deployment
4.Continuous Integration
5.Issue Tracking
REPORTING


1.Code Coverage
2.Branch Coverage
3.Bug Origin:
  - tested code
  - untested code
4.Test/Dev Time:
  - per feature
  - per story
REPORTING

                                        c
                    Only trac k a metri
1.Code Coverage              is useful
                       if it
2.Branch Coverage              urages th
                                         e
                    and enco
3.Bug Origin:                behaviour
                                       !
                      right
  - tested code
  - untested code
4.Test/Dev Time:
  - per feature
  - per story
SKILLS & THE TEAM


               Owners not heroes

                Prepared to fail

              Honest & Disciplined
TDD DOES NOT
CREATE GOOD




a
    CODE

               Wait...
               What ?
TDD DOES NOT
CREATE GOOD    good plan




a
    CODE       good dev
               good code

               bad plan
               bad dev
               bad code
DISASTER RECOVERY
DISASTER RECOVERY



  Untestable code?

 Isolate and contain
         -or-
Create a testable API
DISASTER RECOVERY


   Running late?

    Drop features
         -or-
 Test the happy path
         -or-
    Test core only
DISASTER RECOVERY



   Broken build?

    Fix the test
        -or-
  Disable the test
   (or delete it)
DISASTER RECOVERY



  Team doesn't care

Use incentives/games
        -or-
  Find another job
   You 're worth it !
V                        QUESTIONS?

                          @rowan_m


              i n/3218
        joind.
 ttp://
h
                         thank-you

More Related Content

TDD and Getting Paid

  • 1. Test Driven u Development andaid! f Gettin gP Rowan Merewood Software Eng. / Team Lead Ibuildings
  • 2. WHO AM I? Software Engineer & Technical Team Lead at Ibuildings UK I want to write good code and earn a living @rowan_m m
  • 3. Not ? WHO AM I? s i-am-not-a Cconsultant well-maybe-a-little
  • 4. Not ? WHO AM I? s i-am-not selling-a book
  • 5. Not ? WHO AM I? s i-am-not a-slave-to one=method
  • 6. THE GOOD @ Clean code, smart devs Latest technology Building your career Elitist / Intimidating? DIFFERENT SITUATIONS
  • 7. THE BAD g Disgusting code Devs don't care Career dead-end Changes break the app. Always bug-fixing DIFFERENT SITUATIONS
  • 8. THE UGLY c Good tests are hard Writing tests takes time Time is money You're not an expert (yet...) DIFFERENT SITUATIONS
  • 9. WHAT IS TDD? 1.Decide what you want to do 2.Write a test to show it working 3.Run the test and watch it fail 4.Write just enough code to pass the test 5.Re-run the test (and test suite) 6.Refactor (refine/improve) 7.Re-run tests 8.Repeat
  • 10. WHAT IS TDD? simplify RED H GREEN REFACTOR
  • 11. WHY IS THIS HARD? l Do you know what you want before you code it?
  • 12. WHY IS THIS HARD? l Does your client know what they want? Ever?
  • 13. Train yourself to think like a scientist 1.Hypothesis 2.Repeatable Experiment 3.Conclusions ]
  • 14. ninja Train yourself to think like a scientist ] Kata 1.Hypothesis terally: "form") ( 型 or 形 , li 2.Repeatable movements A set of Experiment 3.Conclusionsain and again you repeat ag ctly. un til can do it perfe Ninja weapon
  • 15. ! DAVE THOMAS co-author of The Pragmatic Programmer Code Kata http://code kata.pragpro g.co m/
  • 16. ROY OSHEROVE - TDD Kata http://osherove.com/tdd-kata-1/ Create a simple String calculator with a method int Add(string numbers) The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”
  • 17. . ROY OSHEROVE - TDD Kata demo
  • 18. Now you're an expert... warning Do not assume you can just start to do this in your project D
  • 19. DON'T BE A HERO Introduce tests all at once... ● You will miss your deadline ● Your tests will not be maintained ● Your team will hate you
  • 20. DIFFERENT APPROACHES Force tests on your client Make your client want the tests L
  • 21. FORCING TESTS to your estimates. Do not compromise your principles. L Add a fixed percentage
  • 22. SELLING TESTS in creating tests. Make the tests a deliverable. L Use tests to define 'done'. Involve the client
  • 23. SELLING TESTS Involve the client in creating tests. Make the tests a deliverable. L Use tests to define 'done'. Fitnesse Framework http://fitnesse.org/
  • 24. SELLING TESTS Involve the client in creating tests. Make the tests a deliverable. L Use tests to define 'done'. Fitnesse Framework http://fitnesse.org/ Selenium http://seleniumhq.org/
  • 25. DON'T BELIEVE THE HYPE Make sure you don't over-promise. Make sure you have the infrastructure and skills NO SILVER BULLETS
  • 26. v INFRASTRUCTURE 1.Unit Testing 2.Acceptance Testing 3.Automated Deployment 4.Continuous Integration 5.Issue Tracking
  • 27. Unit/Acceptanc provides the tec 1.Unit Testing v INFRASTRUCTURE e testing hnical base 2.Acceptance Testing 3.Automated Deployment 4.Continuous Integration 5.Issue Tracking
  • 28. Unit/ Au s v INFRASTRUCTURE e testing Acceptanc eployment ate t d tomthe d echnical base provide a quick test env. 1.Unitows all Testing 2.Acceptance Testing 3.Automated Deployment 4.Continuous Integration 5.Issue Tracking
  • 29. Unit/ Au s ate t dv INFRASTRUCTURE e testing Acceptanc eployment tomthe d echnical rbasen provide ntinuouckIte Co s a qui 1.Unitow makes pr s eg atio ntst env. all Testing ogress visible 2.Acceptance Testing 3.Automated Deployment 4.Continuous Integration 5.Issue Tracking
  • 30. INFRASTRUCTURE Unit/ Au s ate t d Co s a qui s v e testing Acceptanc eployment tomthe d echnical rbasen provide ntinuouckIte eg atio ntst env. ingviallows 1.UnitowIssue Traress sible all Testing og ck makes pr 2.Acceptance rting on TDD repo Testing 3.Automated Deployment 4.Continuous Integration 5.Issue Tracking
  • 31. REPORTING 1.Code Coverage 2.Branch Coverage 3.Bug Origin: - tested code - untested code 4.Test/Dev Time: - per feature - per story
  • 32. REPORTING c Only trac k a metri 1.Code Coverage is useful if it 2.Branch Coverage urages th e and enco 3.Bug Origin: behaviour ! right - tested code - untested code 4.Test/Dev Time: - per feature - per story
  • 33. SKILLS & THE TEAM Owners not heroes Prepared to fail Honest & Disciplined
  • 34. TDD DOES NOT CREATE GOOD a CODE Wait... What ?
  • 35. TDD DOES NOT CREATE GOOD good plan a CODE good dev good code bad plan bad dev bad code
  • 37. DISASTER RECOVERY Untestable code? Isolate and contain -or- Create a testable API
  • 38. DISASTER RECOVERY Running late? Drop features -or- Test the happy path -or- Test core only
  • 39. DISASTER RECOVERY Broken build? Fix the test -or- Disable the test (or delete it)
  • 40. DISASTER RECOVERY Team doesn't care Use incentives/games -or- Find another job You 're worth it !
  • 41. V QUESTIONS? @rowan_m i n/3218 joind. ttp:// h thank-you