unit testing

24
Unit Testing is for Weenies. Important lessons learned from being a bullheaded developer...

Upload: david-rogers

Post on 31-Oct-2014

19 views

Category:

Technology


3 download

DESCRIPTION

There's no shortage of cowboy code-slingers out there in the PHP range. Heck, I used to be one...! You know the types: buckin' bronco projects and spaghetti western logic, firing their guns as many times as they've got bullets... There's a better way, my friends, and it's not just for the yeller-bellied and quail-hearted. Sit by the fire a spell and learn a little about Unit Testing with PHPUnit (or any of them xUnits): what it is, how to do it, and how to sell it to your boss...! 'Cause we all know every cowpoke answers to the man in the big house, after all.

TRANSCRIPT

Page 1: Unit Testing

Unit Testing is for Weenies.

Important lessons learned from being a bullheaded developer...

Page 2: Unit Testing

Unit Testing 101What are these units and why do they need testing?

Page 3: Unit Testing

What is Unit Testing?

In computer programming, unit testing is a software verification and

validation method where the programmer gains confidence that individual

units of source code are fit for use. A unit is the smallest testable part of an

application. In procedural programming a unit may be an individual program,

function, procedure, etc., while in object-oriented programming, the smallest

unit is a method, which may belong to a base/super class, abstract class or

derived/child class.

http://en.wikipedia.org/wiki/Unit_testing

Page 4: Unit Testing

No, really. What is Unit Testing...?

Page 5: Unit Testing

Assertion Testing

IF the assertion fails, THEN display an error message...

Page 6: Unit Testing

Why should we test?

To ensure repeatability of desired behaviors

To identify and remove undesired behaviors

To provide specifications for expected behavior

Page 7: Unit Testing

Why should I spend time testing my code?

How do you know that it works, particularly if it’s part of a big system?

How do you know which part is broken when it breaks?

How do you know that you know which part is broken?

Page 8: Unit Testing

There just isn’t enough time for testing!

How much time do we spend...

Debugging a script or application?

Finding the actual bug?

How many billable hours do we lose?

Don’t we make our own schedules?!?!

Page 9: Unit Testing

I always test my code...$newThing = new Thing();$newThing->doSomething();

$newThing->doSomething($else);if ( $newThing->something == $else ) {

echo “All done!”}

Page 10: Unit Testing

I always test my code...

How can anyone ever repeat that test?

What did it test, anyway?

What do you have to show for the effort?

Page 11: Unit Testing

How should we test?

With the least amount of required human intervention

In a manner that is reliably repeatable, AKA “precise”

In a manner that demonstrates desirable behavior, AKA “accurate”

Page 12: Unit Testing

No, really. HOW?

Page 13: Unit Testing

How to Perform Unit Tests on Objects

Page 14: Unit Testing

1. Pick a test fixture...

2. Start writing tests...

3. Run your tests...

4. Repeat until done...

Page 15: Unit Testing

Gee, Thanks.How about an example?

Page 16: Unit Testing

Doesn’t that seem repetitive?

I’m glad you asked...

Page 17: Unit Testing

Testing is so repetitive...

Page 18: Unit Testing

Testing is so repetitive...

Unit Tests test Objects.

Objects have Inheritance.

Unit Tests are themselves Objects.

Don’t Repeat Yourself.

Page 19: Unit Testing

How to Sell Your Boss on Unit Testing

It’s not me, it’s the psycho I work for...

Page 20: Unit Testing

The Essence of Quality Control is Testing

Testing adds value to work and products

Lessons from other industries...

Toyota makes Good Automobiles.

Sam Adams makes Good Beer.

Unit Testing is Quality Control.

Page 21: Unit Testing

Quality Control Testing MUST BE

Rigorous, by testing everything,

Repeatable, via automated tests,

Producible upon demand,

Rigorous, repeatable, producible tests generate a more stable code base and a more accountable project.

Page 22: Unit Testing

Testing actually saves time and money

Spend less time on tail-end debugging and finding those bugs,

Expose logical flaws and assumptions that we all unintentionally build on,

Build dependencies that work since they’re based on proven assumptions.

Page 23: Unit Testing

Topics to ask Google and Wikipedia about...

JUnit - The granddaddy of ‘em all.

phpUnit - My torture chamber of choice.

RSpec - Unit Testing for Ruby.

Selenium - Graphical Unit Testing.

Test-Driven Development - Way of Life.

Page 24: Unit Testing

Who is this guy?

linkedin.com/in/althex

twitter.com/al_the_x

ethos-development.com

orlandophp.org

David Rogers