SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
Dror Helper
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakes
Milan Vukoje
 
Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the Trenches
Mozaic Works
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
Steven Mak
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Samnang Chhun
 

Tendances (20)

Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
Insoft training day_1
Insoft training day_1Insoft training day_1
Insoft training day_1
 
Real Life Unit Testing
Real Life Unit TestingReal Life Unit Testing
Real Life Unit Testing
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
Debugging
DebuggingDebugging
Debugging
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakes
 
Mixing testing types to improve your testing results
Mixing testing types to improve your testing resultsMixing testing types to improve your testing results
Mixing testing types to improve your testing results
 
Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the Trenches
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automation
 
Testing & should i do it
Testing & should i do itTesting & should i do it
Testing & should i do it
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
Debugging
DebuggingDebugging
Debugging
 
Debugging by induction
Debugging by inductionDebugging by induction
Debugging by induction
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Principles in software debugging
Principles in software debuggingPrinciples in software debugging
Principles in software debugging
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

En vedette

[Challenge:Future] Information Crisis
[Challenge:Future] Information Crisis[Challenge:Future] Information Crisis
[Challenge:Future] Information Crisis
Challenge:Future
 
Christian teaching
Christian teachingChristian teaching
Christian teaching
elizgann
 

En vedette (8)

Media Object File Flt Ops Adv Wx Seq07
Media Object File Flt Ops Adv Wx Seq07Media Object File Flt Ops Adv Wx Seq07
Media Object File Flt Ops Adv Wx Seq07
 
[Challenge:Future] Information Crisis
[Challenge:Future] Information Crisis[Challenge:Future] Information Crisis
[Challenge:Future] Information Crisis
 
Site layout
Site layout Site layout
Site layout
 
Upper floor plan
Upper floor plan Upper floor plan
Upper floor plan
 
Christian teaching
Christian teachingChristian teaching
Christian teaching
 
It application on blogger
It application on bloggerIt application on blogger
It application on blogger
 
Enabling Enterprise Mobility
Enabling Enterprise MobilityEnabling Enterprise Mobility
Enabling Enterprise Mobility
 
Getting More from SCCM
Getting More from SCCMGetting More from SCCM
Getting More from SCCM
 

Similaire à Unit Testing

I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
Peter Presnell
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
Huib Schoots
 
5-Ways-to-Revolutionize-Your-Software-Testing
5-Ways-to-Revolutionize-Your-Software-Testing5-Ways-to-Revolutionize-Your-Software-Testing
5-Ways-to-Revolutionize-Your-Software-Testing
Mary Clemons
 
Computer Software Testing Basics introduced.ppt
Computer Software Testing Basics introduced.pptComputer Software Testing Basics introduced.ppt
Computer Software Testing Basics introduced.ppt
TrevorChinguwo
 
Quality Software With Unit Test
Quality Software With Unit TestQuality Software With Unit Test
Quality Software With Unit Test
alice yang
 

Similaire à Unit Testing (20)

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tips
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
 
Agile test practices
Agile test practicesAgile test practices
Agile test practices
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Automated tests
Automated testsAutomated tests
Automated tests
 
5-Ways-to-Revolutionize-Your-Software-Testing
5-Ways-to-Revolutionize-Your-Software-Testing5-Ways-to-Revolutionize-Your-Software-Testing
5-Ways-to-Revolutionize-Your-Software-Testing
 
Computer Software Testing Basics introduced.ppt
Computer Software Testing Basics introduced.pptComputer Software Testing Basics introduced.ppt
Computer Software Testing Basics introduced.ppt
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 
Quality Software With Unit Test
Quality Software With Unit TestQuality Software With Unit Test
Quality Software With Unit Test
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Unit testing
Unit testingUnit testing
Unit testing
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.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