SlideShare a Scribd company logo
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHPUnit Automated Unit Testing Framework June 5, 2008
Dave Ross “ I grew up around computers, fell in love with the Internet way back in 1994, and built a successful career around my interests in computers and business. My career focus has been on e-commerce, and in my personal time I study issues related to digital identity, trust, and reputation tracking. I’m also an small business owner, an avid Scrabble player, and a b-movie junkie.” 9 years professional development experience PHP developer, certified Java developer LinkedIn profile: http://www.linkedin.com/pub/2/832/9b0 Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
The West Suburban Chicago PHP Meetup Meets first Thursday of every month Usually at the Panera in Wheaton Official Meetup page: http://php.meetup.com/381 Blog: http://suburbanchicagophp.org Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
PHPUnit  is a member of the xUnit family of testing frameworks (SUnit, jUnit, pyUnit...)  Written for PHP 5.x, older versions supported PHP 4.x Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Unit testing: Testing the  smallest  testable parts of an application (Functions, Classes, Macros) Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
The xUnit frameworks provide a way to  automate  unit tests If you automate your tests, the quality of your tests is consistent Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Make it  easy  to test, and you'll do it more often. If you use version control, test before every check-in
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org You can wrap a set of tests into a  test suite A suite tests larger units of your application, even the application itself
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHP itself is tested using automated tests They use a framework called  phpt
The PHPUnit Pocket Guide Tells you everything you need to know when writing PHPUnit test cases Buy the book, or read the HTML version at: http://www.phpunit.de/pocket_guide/index.en.php Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Let's look at a test case!
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org <?php require_once 'PHPUnit/Framework.php'; class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture; protected function setUp() { // Create the Array fixture. $this->fixture = array(); } public function testNewArrayIsEmpty() { // Assert that the size of the Array fixture is 0. $this->assertEquals(0, sizeof($this->fixture)); } public function testArrayContainsAnElement() { // Add an element to the Array fixture. $this->fixture[] = 'Element'; // Assert that the size of the Array fixture is 1. $this->assertEquals(1, sizeof($this->fixture)); } } ?>
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Tests should be run against a known, fixed state called a  fixture setUp() creates this state tearDown() destroys the state and puts things back the way they were
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test cases are implemented as functions whose names start with the word “ test ” This example has: testNewArrayIsEmpty() testArrayContainsAnElement()
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Run  a PHPUnit test case with the  phpunit  command phpunit UnitTest UnitTest.php tells PHPUnit to look for a class UnitTest in the UnitTest.php file (filename is optional)
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org phpunit ArrayTest PHPUnit 3.3.0 by Sebastian Bergmann. .. Time: 0 seconds OK (2 tests)
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Can output test logs to a variety of  formats : GraphViz JSON TAP XML
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test suite + Exported results allows for Continuous Integration
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Continuous integration is a way to automatically run your test suite regularly Once a day... Once an hour... Every time someone checks in code...
Official PHPUnit page: http://www.phpunit.de/ PHPUnit Pocket Guide: http://www.phpunit.de/pocket_guide Effective Unit Testing: http://www.acm.org/ubiquity/views/t_burns_1.html For More Information Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org

More Related Content

What's hot (20)

PPTX
Unit testing plugins: The 5 W's and an H
Tom Jenkins
 
KEY
Phing
Jeremy Coates
 
PPTX
Mocking in python
Ooblioob
 
PDF
TDD for joomla extensions
Roberto Segura
 
PPTX
Php test fest
Barry O Sullivan
 
PPTX
Webdevcon pierrejoye-php54-and-other
Pierre Joye
 
PDF
Is your python application secure? - PyCon Canada - 2015-11-07
Frédéric Harper
 
ODP
PHPNW Test Fest Pre-presentation
Lorna Mitchell
 
PDF
Behaviour Testing and Continuous Integration with Drupal
smithmilner
 
PDF
Php 7 evolution
Félix Gómez López
 
PDF
Build a chatroom!
SheilaJimenezMorejon
 
PPTX
Joomla! JavaScript Testing
Ruchiranga Wickramasinghe
 
PDF
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
OW2
 
PPTX
PyCon Canada 2015 - Is your python application secure
IMMUNIO
 
ODP
IPC 2013 - High Performance PHP with HipHop
Steve Kamerman
 
PDF
Debugging Your Plone Site
cdw9
 
PDF
Git hooks For PHP Developers
Umut IŞIK
 
PDF
AntiVirus Evasion Reconstructed - Veil 3.0
CTruncer
 
PDF
Static analysis for beginners
Antonio Costa aka Cooler_
 
PDF
Introduction to TYPO3 Neos - mUXcamp Worms 2014
Hrishikesh Lele
 
Unit testing plugins: The 5 W's and an H
Tom Jenkins
 
Mocking in python
Ooblioob
 
TDD for joomla extensions
Roberto Segura
 
Php test fest
Barry O Sullivan
 
Webdevcon pierrejoye-php54-and-other
Pierre Joye
 
Is your python application secure? - PyCon Canada - 2015-11-07
Frédéric Harper
 
PHPNW Test Fest Pre-presentation
Lorna Mitchell
 
Behaviour Testing and Continuous Integration with Drupal
smithmilner
 
Php 7 evolution
Félix Gómez López
 
Build a chatroom!
SheilaJimenezMorejon
 
Joomla! JavaScript Testing
Ruchiranga Wickramasinghe
 
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
OW2
 
PyCon Canada 2015 - Is your python application secure
IMMUNIO
 
IPC 2013 - High Performance PHP with HipHop
Steve Kamerman
 
Debugging Your Plone Site
cdw9
 
Git hooks For PHP Developers
Umut IŞIK
 
AntiVirus Evasion Reconstructed - Veil 3.0
CTruncer
 
Static analysis for beginners
Antonio Costa aka Cooler_
 
Introduction to TYPO3 Neos - mUXcamp Worms 2014
Hrishikesh Lele
 

Similar to PHPUnit Automated Unit Testing Framework (20)

PPT
Unit Testing using PHPUnit
varuntaliyan
 
PPTX
PHPUnit: from zero to hero
Jeremy Cook
 
PPT
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
PDF
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
PPT
Test Driven Development with PHPUnit
Mindfire Solutions
 
PPTX
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
PPT
Automated Unit Testing
Mike Lively
 
PPTX
Test in action week 2
Yi-Huan Chan
 
KEY
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
PDF
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
KEY
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
PDF
Php unit (eng)
Anatoliy Okhotnikov
 
PPTX
PHPUnit with CakePHP and Yii
madhavi Ghadge
 
PPT
Phpunit
japan_works
 
ZIP
Test
Eddie Kao
 
PPTX
Unit testing
Prabhat Kumar
 
PDF
Your code are my tests
Michelangelo van Dam
 
PPT
Unit testing
davidahaskins
 
PPT
PHP Unit Testing
Tagged Social
 
KEY
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Unit Testing using PHPUnit
varuntaliyan
 
PHPUnit: from zero to hero
Jeremy Cook
 
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
Test Driven Development with PHPUnit
Mindfire Solutions
 
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
Automated Unit Testing
Mike Lively
 
Test in action week 2
Yi-Huan Chan
 
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
Php unit (eng)
Anatoliy Okhotnikov
 
PHPUnit with CakePHP and Yii
madhavi Ghadge
 
Phpunit
japan_works
 
Test
Eddie Kao
 
Unit testing
Prabhat Kumar
 
Your code are my tests
Michelangelo van Dam
 
Unit testing
davidahaskins
 
PHP Unit Testing
Tagged Social
 
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Ad

More from Dave Ross (20)

KEY
Stylesheets of the future with Sass and Compass
Dave Ross
 
KEY
HTML5 History & Features
Dave Ross
 
PPT
A geek's guide to getting hired
Dave Ross
 
KEY
NoSQL & MongoDB
Dave Ross
 
PDF
Date and Time programming in PHP & Javascript
Dave Ross
 
KEY
Simulated Eye Tracking with Attention Wizard
Dave Ross
 
KEY
What's new in HTML5?
Dave Ross
 
KEY
The Canvas Tag
Dave Ross
 
KEY
Wordpress
Dave Ross
 
PPT
Lamp Stack Optimization
Dave Ross
 
PPT
The FPDF Library
Dave Ross
 
PPT
FirePHP
Dave Ross
 
PPT
Bayesian Inference using b8
Dave Ross
 
PPT
SQL Injection in PHP
Dave Ross
 
KEY
Web App Security: XSS and CSRF
Dave Ross
 
KEY
The Mobile Web: A developer's perspective
Dave Ross
 
KEY
Balsamiq Mockups
Dave Ross
 
KEY
LAMP Optimization
Dave Ross
 
KEY
Lint - PHP & Javascript Code Checking
Dave Ross
 
KEY
Cufon - Javascript Font Replacement
Dave Ross
 
Stylesheets of the future with Sass and Compass
Dave Ross
 
HTML5 History & Features
Dave Ross
 
A geek's guide to getting hired
Dave Ross
 
NoSQL & MongoDB
Dave Ross
 
Date and Time programming in PHP & Javascript
Dave Ross
 
Simulated Eye Tracking with Attention Wizard
Dave Ross
 
What's new in HTML5?
Dave Ross
 
The Canvas Tag
Dave Ross
 
Wordpress
Dave Ross
 
Lamp Stack Optimization
Dave Ross
 
The FPDF Library
Dave Ross
 
FirePHP
Dave Ross
 
Bayesian Inference using b8
Dave Ross
 
SQL Injection in PHP
Dave Ross
 
Web App Security: XSS and CSRF
Dave Ross
 
The Mobile Web: A developer's perspective
Dave Ross
 
Balsamiq Mockups
Dave Ross
 
LAMP Optimization
Dave Ross
 
Lint - PHP & Javascript Code Checking
Dave Ross
 
Cufon - Javascript Font Replacement
Dave Ross
 
Ad

Recently uploaded (20)

PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Practical Applications of AI in Local Government
OnBoard
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 

PHPUnit Automated Unit Testing Framework

  • 1. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHPUnit Automated Unit Testing Framework June 5, 2008
  • 2. Dave Ross “ I grew up around computers, fell in love with the Internet way back in 1994, and built a successful career around my interests in computers and business. My career focus has been on e-commerce, and in my personal time I study issues related to digital identity, trust, and reputation tracking. I’m also an small business owner, an avid Scrabble player, and a b-movie junkie.” 9 years professional development experience PHP developer, certified Java developer LinkedIn profile: http://www.linkedin.com/pub/2/832/9b0 Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 3. The West Suburban Chicago PHP Meetup Meets first Thursday of every month Usually at the Panera in Wheaton Official Meetup page: http://php.meetup.com/381 Blog: http://suburbanchicagophp.org Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 4. PHPUnit is a member of the xUnit family of testing frameworks (SUnit, jUnit, pyUnit...) Written for PHP 5.x, older versions supported PHP 4.x Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 5. Unit testing: Testing the smallest testable parts of an application (Functions, Classes, Macros) Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 6. The xUnit frameworks provide a way to automate unit tests If you automate your tests, the quality of your tests is consistent Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 7. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Make it easy to test, and you'll do it more often. If you use version control, test before every check-in
  • 8. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org You can wrap a set of tests into a test suite A suite tests larger units of your application, even the application itself
  • 9. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHP itself is tested using automated tests They use a framework called phpt
  • 10. The PHPUnit Pocket Guide Tells you everything you need to know when writing PHPUnit test cases Buy the book, or read the HTML version at: http://www.phpunit.de/pocket_guide/index.en.php Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 11. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Let's look at a test case!
  • 12. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org <?php require_once 'PHPUnit/Framework.php'; class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture; protected function setUp() { // Create the Array fixture. $this->fixture = array(); } public function testNewArrayIsEmpty() { // Assert that the size of the Array fixture is 0. $this->assertEquals(0, sizeof($this->fixture)); } public function testArrayContainsAnElement() { // Add an element to the Array fixture. $this->fixture[] = 'Element'; // Assert that the size of the Array fixture is 1. $this->assertEquals(1, sizeof($this->fixture)); } } ?>
  • 13. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Tests should be run against a known, fixed state called a fixture setUp() creates this state tearDown() destroys the state and puts things back the way they were
  • 14. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test cases are implemented as functions whose names start with the word “ test ” This example has: testNewArrayIsEmpty() testArrayContainsAnElement()
  • 15. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Run a PHPUnit test case with the phpunit command phpunit UnitTest UnitTest.php tells PHPUnit to look for a class UnitTest in the UnitTest.php file (filename is optional)
  • 16. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org phpunit ArrayTest PHPUnit 3.3.0 by Sebastian Bergmann. .. Time: 0 seconds OK (2 tests)
  • 17. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Can output test logs to a variety of formats : GraphViz JSON TAP XML
  • 18. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test suite + Exported results allows for Continuous Integration
  • 19. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Continuous integration is a way to automatically run your test suite regularly Once a day... Once an hour... Every time someone checks in code...
  • 20. Official PHPUnit page: http://www.phpunit.de/ PHPUnit Pocket Guide: http://www.phpunit.de/pocket_guide Effective Unit Testing: http://www.acm.org/ubiquity/views/t_burns_1.html For More Information Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 21. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org