SlideShare a Scribd company logo
Unit Testing is for
           Weenies.
Important lessons learned from being a bullheaded developer...
Unit Testing 101
What are these units and why do they need testing?
What is Unit
   Testing?
In computer programming, unit testing is a soft ware 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
No, really. What is
 Unit Testing...?
Assertion Testing




IF the assertion fails,
THEN display an error message...
Why should we test?


To ensure repeatability of desired behaviors
To identify and remove undesired behaviors
To provide specifications for expected behavior
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?
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?
I always test my code...
$newThing = new Thing();
$newThing->doSomething();
$newThing->doSomething($else);
if ( $newThing->something == $else ) {
    echo “All done!”
}
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?
How should we test?

With the least amount of required human
inter vention
In a manner that is reliably repeatable, AKA
“precise”
In a manner that demonstrates desirable
behavior, AKA “
              accurate”
No, really. HOW?
How to Perform Unit
  Tests on Objects
1. Pick a test fixture...

2. Start writing tests...

3. Run your tests...

4. Repeat until done...
Gee, Thanks.
 How about an example?
Doesn’t that seem
   repetitive?
    I’m glad you asked...
Testing is so repetitive...
Testing is so repetitive...
Unit Tests test Objects.
Objects have Inheritance.
Unit Tests are themselves Objects.
Don’t Repeat Yourself.
How to Sell Your Boss
  on Unit Testing
   It’s not me, it’s the psycho I work for...
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.
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.
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.
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.
Who is this guy?

linkedin.com/in/althex

t witter.com/al_the_x

ethos-development.com    David Rogers
orlandophp.org

More Related Content

PPTX
The problem with tdd
DOC
Questions1
PDF
Unit testing (workshop)
PPS
Why Unit Testingl
PPTX
An Introduction to Unit Testing
ODP
@LinkingNote annotation in YATSPEC
PDF
Unit testing in PHP
ODP
The Art Of Debugging
The problem with tdd
Questions1
Unit testing (workshop)
Why Unit Testingl
An Introduction to Unit Testing
@LinkingNote annotation in YATSPEC
Unit testing in PHP
The Art Of Debugging

What's hot (20)

PDF
Effective Unit Testing
PPTX
Insoft training day_1
PPTX
Real Life Unit Testing
PDF
Unit Test + Functional Programming = Love
PPTX
Benefit From Unit Testing In The Real World
PPTX
PPTX
Advanced unit testing – real life examples and mistakes
PPTX
Mixing testing types to improve your testing results
PDF
Alexandru Bolboaca - Unit Testing from the Trenches
PPT
Lessons learned on software testing automation
PPTX
Testing & should i do it
PPT
.Net Debugging Techniques
PPT
Debugging
PPSX
Debugging by induction
ZIP
Test Driven Development
PDF
Is this how you hate unit testing?
PPTX
Principles in software debugging
PDF
How to complement TDD with static analysis
PPTX
Test Driven Development
PDF
Test Driven Development
Effective Unit Testing
Insoft training day_1
Real Life Unit Testing
Unit Test + Functional Programming = Love
Benefit From Unit Testing In The Real World
Advanced unit testing – real life examples and mistakes
Mixing testing types to improve your testing results
Alexandru Bolboaca - Unit Testing from the Trenches
Lessons learned on software testing automation
Testing & should i do it
.Net Debugging Techniques
Debugging
Debugging by induction
Test Driven Development
Is this how you hate unit testing?
Principles in software debugging
How to complement TDD with static analysis
Test Driven Development
Test Driven Development
Ad

Viewers also liked (8)

PDF
Media Object File Flt Ops Adv Wx Seq07
PPT
[Challenge:Future] Information Crisis
PDF
Upper floor plan
PPTX
Christian teaching
PPTX
It application on blogger
PPTX
Enabling Enterprise Mobility
PDF
Getting More from SCCM
Media Object File Flt Ops Adv Wx Seq07
[Challenge:Future] Information Crisis
Upper floor plan
Christian teaching
It application on blogger
Enabling Enterprise Mobility
Getting More from SCCM
Ad

Similar to Unit Testing (20)

PPS
Why Unit Testingl
PPS
Why unit testingl
PPTX
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
PPTX
Practical unit testing tips
PPS
Unit Testing
ODP
I Smell A RAT- Rapid Application Testing
PPTX
Agile test practices
PDF
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
PPTX
Exploratory testing
PPTX
TDD Best Practices
PPT
Unit testing
PPTX
Test-Driven Development In Action
PPTX
Automated tests
PDF
5-Ways-to-Revolutionize-Your-Software-Testing
PPT
Computer Software Testing Basics introduced.ppt
PDF
Win at life with unit testing
PPT
Quality Software With Unit Test
PDF
Test Drive Development
PDF
TDD Workshop UTN 2012
PPTX
Unit testing
Why Unit Testingl
Why unit testingl
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
Practical unit testing tips
Unit Testing
I Smell A RAT- Rapid Application Testing
Agile test practices
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
Exploratory testing
TDD Best Practices
Unit testing
Test-Driven Development In Action
Automated tests
5-Ways-to-Revolutionize-Your-Software-Testing
Computer Software Testing Basics introduced.ppt
Win at life with unit testing
Quality Software With Unit Test
Test Drive Development
TDD Workshop UTN 2012
Unit testing

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Tartificialntelligence_presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
August Patch Tuesday
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
Heart disease approach using modified random forest and particle swarm optimi...
Programs and apps: productivity, graphics, security and other tools
A comparative study of natural language inference in Swahili using monolingua...
Digital-Transformation-Roadmap-for-Companies.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Encapsulation_ Review paper, used for researhc scholars
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Tartificialntelligence_presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
August Patch Tuesday
Agricultural_Statistics_at_a_Glance_2022_0.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf

Unit Testing

  • 1. Unit Testing is for Weenies. Important lessons learned from being a bullheaded developer...
  • 2. Unit Testing 101 What are these units and why do they need testing?
  • 3. What is Unit Testing? In computer programming, unit testing is a soft ware 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
  • 4. No, really. What is Unit Testing...?
  • 5. Assertion Testing IF the assertion fails, THEN display an error message...
  • 6. Why should we test? To ensure repeatability of desired behaviors To identify and remove undesired behaviors To provide specifications for expected behavior
  • 7. 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?
  • 8. 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?
  • 9. I always test my code... $newThing = new Thing(); $newThing->doSomething(); $newThing->doSomething($else); if ( $newThing->something == $else ) { echo “All done!” }
  • 10. 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?
  • 11. How should we test? With the least amount of required human inter vention In a manner that is reliably repeatable, AKA “precise” In a manner that demonstrates desirable behavior, AKA “ accurate”
  • 13. How to Perform Unit Tests on Objects
  • 14. 1. Pick a test fixture... 2. Start writing tests... 3. Run your tests... 4. Repeat until done...
  • 15. Gee, Thanks. How about an example?
  • 16. Doesn’t that seem repetitive? I’m glad you asked...
  • 17. Testing is so repetitive...
  • 18. Testing is so repetitive... Unit Tests test Objects. Objects have Inheritance. Unit Tests are themselves Objects. Don’t Repeat Yourself.
  • 19. How to Sell Your Boss on Unit Testing It’s not me, it’s the psycho I work for...
  • 20. 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.
  • 21. 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.
  • 22. 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.
  • 23. 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.
  • 24. Who is this guy? linkedin.com/in/althex t witter.com/al_the_x ethos-development.com David Rogers orlandophp.org