Slide 1

Slide 1 text

WHY YOU CAN'T TEST Chris Hartjes - CakeFest 2014 August 24, 2014

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Testing Is Hard

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

7 Obstacles

Slide 6

Slide 6 text

Configuration Configuring tools is difficult

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Configuration Composer + Packagist = library management Keeps dependencies as part of the project

Slide 9

Slide 9 text

Configuration { "require": { "fabpot/goutte": "1.0.*@dev", "igorw/yolo": "~42.0@dev" } }

Slide 10

Slide 10 text

Configuration Making your own packages available is easy Standard locations for files reduces confusion

Slide 11

Slide 11 text

Configuration Avoid “my project is SOOOOO unique” mentality Makes it increasingly difficult to integrate other projects Convention over configuration matters

Slide 12

Slide 12 text

Education Developers not taught how to test

Slide 13

Slide 13 text

Education

Slide 14

Slide 14 text

Education Impossible to learn how to write tests in isolation Mentorships are awesome! (http://phpmentoring.org) Talking about mentoring is awesome (#phpmentoring on Freenode)

Slide 15

Slide 15 text

Education It takes two to test

Slide 16

Slide 16 text

Education

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Education

Slide 19

Slide 19 text

Coupling Tightly-coupled code common

Slide 20

Slide 20 text

Coupling Learn about dependency injection Learn about Demeter’s Law Understand WHY coupling is bad

Slide 21

Slide 21 text

Coupling You probably know DI by a less-complicated name You probably already do it

Slide 22

Slide 22 text

Coupling

Slide 23

Slide 23 text

Coupling DI Containers / Service Locators Constructor injection Setter injection

Slide 24

Slide 24 text

Coupling Containers are simply a way to store something for later retrieval Think “define stuff in my bootstrap sequence”

Slide 25

Slide 25 text

Coupling

Slide 26

Slide 26 text

Coupling

Slide 27

Slide 27 text

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!

Slide 28

Slide 28 text

Dependencies Too many dependencies

Slide 29

Slide 29 text

Dependencies You never know it until you try to create mocks for them Every dependency you add needs to be justified

Slide 30

Slide 30 text

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?

Slide 31

Slide 31 text

Dependencies http://www.littlehart.net/atthekeyboard/2012/03/27/ metatesting-understanding-mock-objects/

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Misconceptions Tests can help you go home from work on time every day

Slide 36

Slide 36 text

Misconceptions Bugs found in development cost $X Bugs found by QA cost $2X Bugs found in production cost $10X

Slide 37

Slide 37 text

Environments Lack of control over environments

Slide 38

Slide 38 text

Environments Composer can play double duty Vagrant / other virtual machines are key Repeatable automated processes are key

Slide 39

Slide 39 text

Environments Composer lets you lock down the environment Easy to specify versions of all libraries Reduce likelihood of “works on my machine”

Slide 40

Slide 40 text

Environments http://vagrantup.com Learn it, live it, love it

Slide 41

Slide 41 text

Environments People make mistakes all the tie Computers make mistakes you tell them to Examine procedures carefully to find automation opportunities

Slide 42

Slide 42 text

Motivation Maintenance programming sucks

Slide 43

Slide 43 text

Motivation Good test suites make bug fixes easy Good test suites make it easier to integrate new things

Slide 44

Slide 44 text

Motivation Good test suites mean more time worrying about big problems Good test suites mean less time worrying about regressions

Slide 45

Slide 45 text

Shameless Self-Promotion http://grumpy-testing.com http://grumpy-phpunit.com

Slide 46

Slide 46 text

Feed My Ego [email protected] @grmpyprogrammer ASK ME ANYTHING - I READ ALL EMAIL AND TWEETS https://joind.in/11602