Why You Can't Test

Why You Can't Test

Slides for a talk I gave at CakeFest 2014 about obstacles developers face when they decide to start writing automated tests for their code.

27601bca8f38e75cbcf9d2dc843f0b32?s=128

Chris Hartjes

August 24, 2014
Tweet

Transcript

  1. WHY YOU CAN'T TEST Chris Hartjes - CakeFest 2014 August

    24, 2014
  2. None
  3. Testing Is Hard

  4. None
  5. 7 Obstacles

  6. Configuration Configuring tools is difficult

  7. Configuration Use Composer (http://getcomposer.org) to isolate tools to your project

    Modify your project to fit the defaults of tools whenever possible Avoid fighting with tools but also resist urge to write your own
  8. Configuration Composer + Packagist = library management Keeps dependencies as

    part of the project
  9. Configuration { "require": { "fabpot/goutte": "1.0.*@dev", "igorw/yolo": "~42.0@dev" } }

  10. Configuration Making your own packages available is easy Standard locations

    for files reduces confusion
  11. Configuration Avoid “my project is SOOOOO unique” mentality Makes it

    increasingly difficult to integrate other projects Convention over configuration matters
  12. Education Developers not taught how to test

  13. Education

  14. Education Impossible to learn how to write tests in isolation

    Mentorships are awesome! (http://phpmentoring.org) Talking about mentoring is awesome (#phpmentoring on Freenode)
  15. Education It takes two to test

  16. Education

  17. Education Mentoring is a great way to make connections My

    own apprentices have gone on to success Easy way to give back to the community
  18. Education

  19. Coupling Tightly-coupled code common

  20. Coupling Learn about dependency injection Learn about Demeter’s Law Understand

    WHY coupling is bad
  21. Coupling You probably know DI by a less-complicated name You

    probably already do it
  22. Coupling

  23. Coupling DI Containers / Service Locators Constructor injection Setter injection

  24. Coupling Containers are simply a way to store something for

    later retrieval Think “define stuff in my bootstrap sequence”
  25. Coupling

  26. Coupling

  27. Coupling Dependency Injection Containers and Service Locators are simply globally-available

    ways to retrieve stuff Be sure to not make you code dependant on the container / locator!
  28. Dependencies Too many dependencies

  29. Dependencies You never know it until you try to create

    mocks for them Every dependency you add needs to be justified
  30. Dependencies “Mocking” is the creation of copies of dependencies the

    code you are testing has You create those copies in a specific state Easiest way to see if your code is testable — can you easily inject dependencies in?
  31. Dependencies http://www.littlehart.net/atthekeyboard/2012/03/27/ metatesting-understanding-mock-objects/

  32. Misconceptions “You are paid to write code, not tests!”

  33. Misconceptions Getting paid not to write code, but to solve

    problems Many people discount the costs of fixing bugs Many people discount the costs of missed opportunities bugs create
  34. Misconceptions TDD is about shifting bug-fixing to a cheaper part

    of the process TDD is a design pattern! 20% to 40% more time for 40% to 90% fewer bugs
  35. Misconceptions Tests can help you go home from work on

    time every day
  36. Misconceptions Bugs found in development cost $X Bugs found by

    QA cost $2X Bugs found in production cost $10X
  37. Environments Lack of control over environments

  38. Environments Composer can play double duty Vagrant / other virtual

    machines are key Repeatable automated processes are key
  39. Environments Composer lets you lock down the environment Easy to

    specify versions of all libraries Reduce likelihood of “works on my machine”
  40. Environments http://vagrantup.com Learn it, live it, love it

  41. Environments People make mistakes all the tie Computers make mistakes

    you tell them to Examine procedures carefully to find automation opportunities
  42. Motivation Maintenance programming sucks

  43. Motivation Good test suites make bug fixes easy Good test

    suites make it easier to integrate new things
  44. Motivation Good test suites mean more time worrying about big

    problems Good test suites mean less time worrying about regressions
  45. Shameless Self-Promotion http://grumpy-testing.com http://grumpy-phpunit.com

  46. Feed My Ego chartjes@littlehart.net @grmpyprogrammer ASK ME ANYTHING - I

    READ ALL EMAIL AND TWEETS https://joind.in/11602