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

KEY
An introduction to Phing the PHP build system (PHPDay, May 2012)
KEY
An introduction to Phing the PHP build system
PPTX
TDD in Go with Ginkgo and Gomega
PDF
Debugging, Monitoring and Profiling in TYPO3
 
PDF
The typo3.org Relaunch Project
 
PDF
Automated Testing in WordPress, Really?!
PDF
TDD in Python With Pytest
ODP
Neo4j Graph Database, from PHP
An introduction to Phing the PHP build system (PHPDay, May 2012)
An introduction to Phing the PHP build system
TDD in Go with Ginkgo and Gomega
Debugging, Monitoring and Profiling in TYPO3
 
The typo3.org Relaunch Project
 
Automated Testing in WordPress, Really?!
TDD in Python With Pytest
Neo4j Graph Database, from PHP

What's hot (20)

PPTX
Unit testing plugins: The 5 W's and an H
KEY
PPTX
Mocking in python
PDF
TDD for joomla extensions
PPTX
Php test fest
PPTX
Webdevcon pierrejoye-php54-and-other
PDF
Is your python application secure? - PyCon Canada - 2015-11-07
ODP
PHPNW Test Fest Pre-presentation
PDF
Behaviour Testing and Continuous Integration with Drupal
PDF
Php 7 evolution
PDF
Build a chatroom!
PPTX
Joomla! JavaScript Testing
PDF
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
 
PPTX
PyCon Canada 2015 - Is your python application secure
ODP
IPC 2013 - High Performance PHP with HipHop
PDF
Debugging Your Plone Site
PDF
Git hooks For PHP Developers
PDF
AntiVirus Evasion Reconstructed - Veil 3.0
PDF
Static analysis for beginners
PDF
Introduction to TYPO3 Neos - mUXcamp Worms 2014
Unit testing plugins: The 5 W's and an H
Mocking in python
TDD for joomla extensions
Php test fest
Webdevcon pierrejoye-php54-and-other
Is your python application secure? - PyCon Canada - 2015-11-07
PHPNW Test Fest Pre-presentation
Behaviour Testing and Continuous Integration with Drupal
Php 7 evolution
Build a chatroom!
Joomla! JavaScript Testing
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
 
PyCon Canada 2015 - Is your python application secure
IPC 2013 - High Performance PHP with HipHop
Debugging Your Plone Site
Git hooks For PHP Developers
AntiVirus Evasion Reconstructed - Veil 3.0
Static analysis for beginners
Introduction to TYPO3 Neos - mUXcamp Worms 2014
Ad

Similar to PHPUnit Automated Unit Testing Framework (20)

PDF
Fighting Fear-Driven-Development With PHPUnit
PPS
Simplify your professional web development with symfony
PDF
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
PPT
Automated Unit Testing
PDF
Leveling Up With Unit Testing - LonghornPHP 2022
ODP
Passing The Joel Test In The PHP World
PDF
Automatic testing and quality assurance for WordPress plugins and themes
PDF
Behavior & Specification Driven Development in PHP - #OpenWest
PDF
PHPUnit best practices presentation
KEY
Workshop quality assurance for php projects tek12
PDF
Intro to PHP Testing
KEY
BDD with Behat and Symfony2
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
PDF
Current state-of-php
PPT
Pragmatic Parallels: Java and JavaScript
PDF
2013 - Dustin whittle - Escalando PHP en la vida real
KEY
Prepare for PHP Test Fest 2009
PDF
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
PDF
Php unit (eng)
PDF
Your code are my tests
Fighting Fear-Driven-Development With PHPUnit
Simplify your professional web development with symfony
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Automated Unit Testing
Leveling Up With Unit Testing - LonghornPHP 2022
Passing The Joel Test In The PHP World
Automatic testing and quality assurance for WordPress plugins and themes
Behavior & Specification Driven Development in PHP - #OpenWest
PHPUnit best practices presentation
Workshop quality assurance for php projects tek12
Intro to PHP Testing
BDD with Behat and Symfony2
Continuous Delivery - Automate & Build Better Software with Travis CI
Current state-of-php
Pragmatic Parallels: Java and JavaScript
2013 - Dustin whittle - Escalando PHP en la vida real
Prepare for PHP Test Fest 2009
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Php unit (eng)
Your code are my tests
Ad

More from Dave Ross (20)

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

Recently uploaded (20)

PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Tartificialntelligence_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPT
Geologic Time for studying geology for geologist
PDF
Getting Started with Data Integration: FME Form 101
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
August Patch Tuesday
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Architecture types and enterprise applications.pdf
O2C Customer Invoices to Receipt V15A.pptx
A comparative study of natural language inference in Swahili using monolingua...
Tartificialntelligence_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Geologic Time for studying geology for geologist
Getting Started with Data Integration: FME Form 101
Taming the Chaos: How to Turn Unstructured Data into Decisions
DP Operators-handbook-extract for the Mautical Institute
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
observCloud-Native Containerability and monitoring.pptx
Hybrid model detection and classification of lung cancer
August Patch Tuesday
Hindi spoken digit analysis for native and non-native speakers
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
A review of recent deep learning applications in wood surface defect identifi...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Architecture types and enterprise applications.pdf

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